Java Chapters

Java Program to receive values of latitude and longitude in degress, of two places on earth and outputs the distance between them in nautical miles. The formula for distance in nautical is :
D=3963 cos-1 (sinL1sinL2+cosL1cosL2*cos(G2-G1))

Structure of JAVA Programs - Overview
import java.util.Scanner;
import java.lang.*;

public class Program 
{
    public static void main( String[] args ) 
    {
        double L1, L2, G1, G2, D;
        Scanner reader = new Scanner(System.in);
        
        System.out.print("Enter Two Values of Lattitude : ");
        L1 = reader.nextDouble();
        L2 = reader.nextDouble();
        
        System.out.print("\nEnter Two Values of Longitude : ");
        G1 = reader.nextDouble();
        G2 = reader.nextDouble();
        
        D = 3963 * Math.acos(Math.sin(L1) * Math.sin(L2) + Math.cos(L1) * Math.cos(L2) * Math.cos(G2 - G1));
        
        System.out.print("\n\nDistance is : " + D);
    }
}

Output :
Enter Two Values of Lattitude : 50
100
Enter Two Values of Longitude : 150
200

Distance is : 1427.6118389059525

Leave a comment
Recent Comments
No Comments