-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest14.java
More file actions
43 lines (37 loc) · 1.04 KB
/
Copy pathTest14.java
File metadata and controls
43 lines (37 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package programmers;
import java.util.ArrayList;
import java.util.Comparator;
//import java.util.Collections;
////////////////////////////////////////////////////////////////////
public class Test14 {
public int[] solution(int[] arr, int divisor) {
int[] answer = {};
for(int i=0; i<arr.length;i++){
if(arr[i]%divisor==0){
answer[i]=arr[i];
}
}
return answer;
}
public static void main(String[] args) {
Test14 arr = new Test14();
int[] a = {5,9,7,10};
int b = 5;
ArrayList<Integer> ar = new ArrayList<>();
for (int i = 0; i < a.length; i++) {
if (a[i] % b == 0) {
ar.add(a[i]);
}
}
if (ar.isEmpty()) {
ar.add(-1);
}
ar.sort(Comparator.naturalOrder());
System.out.println(ar);
// int[] result = {};
// for (int i = 0; i < ar.size(); i++) {
// result[i]=ar.get(i);
// }
// System.out.println(result);
}
}