-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathHomeWork.java
More file actions
49 lines (37 loc) · 1.64 KB
/
Copy pathHomeWork.java
File metadata and controls
49 lines (37 loc) · 1.64 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
44
45
46
47
48
49
import java.util.ArrayList;
import java.util.Collections;
public class HomeWork {
public String counter (Integer int1, Integer int2,Integer int3, Integer int4){
StringBuilder result=new StringBuilder();
ArrayList <Integer> arrayOfInts = new ArrayList<>();
arrayOfInts.add(int1);
arrayOfInts.add(int2);
arrayOfInts.add(int3);
arrayOfInts.add(int4);
Collections.sort(arrayOfInts);
for (int i=0; i<arrayOfInts.size(); i++){
if (arrayOfInts.get(0)==arrayOfInts.get(i)){
result.append("Minimum:" + arrayOfInts.get(i) + "\n");
}
}
result.append("Maximum:" + Collections.max(arrayOfInts) + "\n");
for (int i=0; i<arrayOfInts.size(); i++) {
if (arrayOfInts.get(i)%2!=0){
result.append(arrayOfInts.get(i) + "is odd number" + "\n");
}else {
result.append(arrayOfInts.get(i) + "is even number" + "\n");
}
}
for (int i=0; i<arrayOfInts.size()-1; i++) {
if (arrayOfInts.get(i) % arrayOfInts.get(i + 1) == 0) {
result.append(arrayOfInts.get(i) + " divided without remainder on " + arrayOfInts.get(i + 1) + "\n");
}
}
if (Math.abs(10-arrayOfInts.get(2))<Math.abs(10-arrayOfInts.get(3))){
result.append(arrayOfInts.get(2) + " is closer to ten " + "\n");
}else {
result.append(arrayOfInts.get(3) + " is closer to ten " + "\n");
}
return result.toString();
}
}