So I am making a program that will output the greatest and least greatest values of the users' input of longitude and latitude. Interestingly enough, the program actaully runs and works! But it keeps getting an error as such:
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:864)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextInt(Scanner.java:2117)
at java.util.Scanner.nextInt(Scanner.java:2076)
at Lesson_20_Activity.main(Main.java:328)
at Ideone.assertRegex(Main.java:85)
at Ideone.assertRegex(Main.java:76)
at Ideone.test(Main.java:40)
at Ideone.main(Main.java:29)
I have a feeling it is something to do with Scanner class, but I've checked to see if everything is right at least a dozen times...
import java.util.Scanner;
import java.lang.Math;
class Lesson_20_Activity {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
double lat=0;
double lon=0;
int num = 1;
//min variables
double xlat=Integer.MAX_VALUE;
double xlon=Integer.MAX_VALUE;
//max variables
double ylat=Integer.MIN_VALUE;
double ylon=Integer.MIN_VALUE;
/* the program wants the greatest and lowest values entered in latitude longitude.
*/
while (num == 1){
System.out.println("Please enter the latitude: ");
lat = scan.nextDouble();
//establishes the largest input
if(lat>-90&&lat<90&&lat>ylat){
ylat=lat;
}
//establishes the smallest input
if(lat>-90&&lat<90&&lat<xlat){
xlat=lat;
}
System.out.println("Please enter the longitude: ");
lon = scan.nextDouble();
//establishes the largest input
if(lon>-180&&lon<180&&lon>ylon){
ylon=lon;
}
//establishes the smallest input
if(lon>-180&&lon<180&&lon<xlon){
xlon=lon;
}
System.out.println("Would you like to enter another location?");
num = scan.nextInt();
}
System.out.println("Farthest North: " + ylat);
System.out.println("Farthest South: " + xlat);
System.out.println("Farthest East: " + ylon);
System.out.println("Farthest West: " + xlon);
}
}