Advertisement
apez1

Term 1: Lesson 20 - Coding Activity (no array)

Oct 11th, 2018
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Lesson_20_Activity {
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.             Scanner scan= new Scanner(System.in);
  8.              int x = 1;
  9.              double lon = 0;
  10.              double lat = 0;
  11.              double maxlat = -90;
  12.              double minlat = 90;
  13.              double maxlon = -180;
  14.              double minlon = 180;
  15.  
  16.              while (x == 1)
  17.             {  
  18.              System.out.println("Please enter the latitude:");
  19.              lat = scan.nextDouble();
  20.  
  21.              System.out.println("Please enter the longitude:");
  22.              lon = scan.nextDouble();
  23.  
  24.              if ((lat < -90 || lat > 90) || (lon < -180 || lon > 180)) {
  25.                  System.out.println("Incorrect Latitude or Longitude");
  26.              }
  27.              else {
  28.  
  29.              if (lat > maxlat)
  30.                maxlat = lat;
  31.              if (lat < minlat)
  32.                minlat = lat;
  33.              if (lon > maxlon)
  34.                maxlon = lon;
  35.              if (lon < minlon)
  36.                minlon = lon;
  37.  
  38.              System.out.println("Would you like to enter another location?");
  39.                x = scan.nextInt();
  40.              }
  41.             }
  42.             System.out.println("Farthest North: " + maxlat);
  43.             System.out.println("Farthest South: " + minlat);
  44.             System.out.println("Farthest East: " + maxlon);
  45.             System.out.println("Farthest West: " + minlon);
  46.        
  47.        
  48.     }
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement