-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.java
46 lines (44 loc) · 1.4 KB
/
app.java
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
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class app {
public static void main(String[] args) {
ArrayList<Object> arr = new ArrayList<>(Arrays.asList(0.22, 0.66, 0.23, 0.9, 0.1));
ArrayList<List> list = new ArrayList<>();
System.out.println(arr.get(0).getClass());
Double max = (Double) arr.get(0);
Double min = (Double) arr.get(0);
for (int i = 0; i < arr.size(); i++) {
if ((double)arr.get(i) > max) {
max = (double)arr.get(i);
}
}
for (int i = 0; i < arr.size(); i++) {
if ((double)arr.get(i) < min) {
min = (double)arr.get(i);
}
}
int bucklen = 5;
double oko = (float) (max - min) / (int) bucklen;
oko = Math.round(oko * 1000.0) / 1000.0;
for (int i = 0; i < bucklen; i++) {
list.add(new ArrayList<>());
}
for (int i = 0; i < arr.size(); i++) {
if (i == arr.indexOf(min)) {
list.get((int) (long) (Math.round(((((double)arr.get(i))-min)/oko)))).add(arr.get(i));
}
else {
list.get((int) (long) (Math.round(((((double)arr.get(i))-min)/oko-1)))).add(arr.get(i));
}
}
for (int i = 0; i < bucklen; i++) {
list.get(i).sort(null);
for (int j = 0; j < list.get(i).size(); j++) {
System.out.print(list.get(i).get(j) + " ");
}
}
System.out.print("\n");
// System.out.println(list);
}
}