Advertisement
mcnealk

Project 5

Oct 6th, 2014
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. import java.util.*;
  2. /**
  3. * Write a description of class Project5 here.
  4. * Kailey McNeal
  5. * 10-2-14
  6. * Project #5
  7. */
  8. public class Project5
  9. {
  10. public static void main (String[] args)
  11. {
  12. Scanner console=new Scanner (System.in);
  13. System.out.print("What is the latitude of the 1st city? ");
  14. double lat1=console.nextDouble();
  15. System.out.print("What is the longitude of the 1st city? ");
  16. double longi1=console.nextDouble();
  17. System.out.print("What is the latitude of the 2nd city? ");
  18. double lat2=console.nextDouble();
  19. System.out.print("What is the longitude of the 2nd city? ");
  20. double longi2=console.nextDouble();
  21. longi1=Math.toRadians(longi1);
  22. lat1=Math.toRadians(lat1);
  23. longi2=Math.toRadians(longi2);
  24. lat2=Math.toRadians(lat2);
  25. double longdis=Math.max(longi1, longi2)-Math.min(longi1, longi2); //longitudinal distance
  26. double angdiff=Math.acos(Math.sin(lat1)*Math.sin(lat2)+Math.cos(lat1)*Math.cos(lat2)*Math.cos(longdis)); //angular difference
  27. double answer=angdiff*6372.795;
  28. System.out.println(answer + "km");
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement