-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathExercise.java
More file actions
29 lines (24 loc) · 806 Bytes
/
Exercise.java
File metadata and controls
29 lines (24 loc) · 806 Bytes
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
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
public class Exercise {
public static void main(String[] args) {
ArrayList<Coordinate> coordinates = new ArrayList<>();
coordinates.add(new Coordinate(3, 5));
coordinates.add(new Coordinate(7, 6));
coordinates.add(new Coordinate(2, 1));
coordinates.add(new Coordinate(6, 8));
coordinates.add(new Coordinate(1, 9));
Collections.sort(
coordinates,
new Comparator<Coordinate>() {
@Override
public int compare(Coordinate c1, Coordinate c2) {
return Integer.valueOf(c1.getY()).compareTo(c2.getY());
}
});
for (Coordinate c : coordinates) {
System.out.println(c + ": " + c.getDistanceToOriginPoint());
}
}
}