Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * find the largest number in an array arlat and arlon
- * remove a number from the array if out of range
- */
- package project;
- import java.util.*;
- import java.util.Scanner;
- import java.util.Collections;
- public class Yourmom {
- public static void main(String[] args) {
- double lat;
- double lon;
- int reply = 1;
- ArrayList <Double> arlat = new ArrayList<Double>();
- //double arlat[] = new double[7];
- //double arlon[] = new double[7];
- ArrayList <Double> arlon = new ArrayList<Double>();
- Scanner scanner = new Scanner(System.in);
- while(reply != 0) {
- int c = 0;
- c++;
- System.out.println("Please enter the latitude:");
- lat = scanner.nextDouble();
- //arlat[c]=lat;
- arlat.add(lat);
- System.out.println("Please enter the longitude:");
- lon = scanner.nextDouble();
- //arlon[c]=lon;
- arlon.add(lon);
- int flag = 0;
- if(lat < -90 || lat > 90 ) {
- flag = 1;
- }
- if(lon < -180 || lon > 180 ) {
- flag = 1;
- }
- if(flag == 1) {
- System.out.println("Incorrect Latitude or Longitude");
- reply = 1;
- //remove numbers from array
- arlon.remove(lon);
- arlat.remove(lat);
- }
- if(flag != 1) {
- System.out.println("Would you like to enter another location?");
- reply = scanner.nextInt();
- }
- }
- double largestlat = Collections.max(arlat);
- double smallestlat = Collections.min(arlat);
- double largestlon = Collections.max(arlon);
- double smallestlon = Collections.min(arlon);
- if(reply ==0) {
- System.out.println("Farthest North: " + largestlat);
- System.out.println("Farthest South: " + smallestlat); //*
- System.out.println("Farthest East: " + largestlon) ;
- System.out.println("Farthest West: " + smallestlon); //*
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement