I tried using the top formula of distance from the other question but it display 'NaN'; can someone tell me where I got it wrong. Also, sometimes it doesn't go 'NaN' but the answer is still inaccurate. I'm a beginner.
import java.util.Scanner;
public class Great_Circle{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double r = 6371.0;
double x1 = scanner.nextDouble();
double y1 = scanner.nextDouble();
double x2 = scanner.nextDouble();
double y2 = scanner.nextDouble();
double distance = 2 * r * Math.asin(Math.sqrt(Math.pow(Math.sin((x2 - x1) / 2),2 +
Math.cos(x2) * Math.pow(Math.sin((y2 - y1) / 2),2))));
System.out.println(distance + " kilometers ");
}
}