Cristiano Magro
2025-10-05 e877a220f1fef50f9ebef7b64f1784273ca7f555
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public class GreatCircle {
    public static void main(String[] args) {
        double x1 = Double.parseDouble(args[0]);
        double y1 = Double.parseDouble(args[1]);
        double x2 = Double.parseDouble(args[2]);
        double y2 = Double.parseDouble(args[3]);
 
        double r = 6371.0; // Earth radius
 
        double dx = Math.toRadians(x2 - x1) / 2.0;
        double dy = Math.toRadians(y2 - y1) / 2.0;
 
        double under = Math.sin(dx) * Math.sin(dx) +
                Math.cos(Math.toRadians(x1)) * Math.cos(Math.toRadians(x2))
                        * Math.sin(dy) * Math.sin(dy);
 
        double distance = 2.0 * r * Math.asin(Math.sqrt(under));
 
        System.out.println(distance + " kilometers");
    }
}