This is for an online assignment. The goal is to accept two inputs (in this code, the x and y variables) multiple times and then print the largest and smallest value of each variable. Here is the code:
import java.io.*;
import static java.lang.System.*;
import java.util.Scanner;
import java.lang.Math;
class Lesson_20_Activity_One{
public static void main (String str[]) throws IOException {
Scanner scan = new Scanner(System.in);
double x; //the latitude input
double y; //the longitude input
double n = -90; //the maximum north value
double e = -180; //the maximum east value
double s = 90; //the maximum south value
double w = 180; //the maximum west value
int escape = 1; //the value that dictates when it's time to exit the while loop
while (escape == 1) {
System.out.println("Please enter the latitude:");
x = scan.nextDouble();
System.out.println("Please enter the longitude:");
y = scan.nextDouble();
if ((x>n) && (x<=90))
n = x;
if ((x<s) && (x>=-90))
s = x;
if ((y>e) && (y<=180))
e = y;
if ((y<w) && (y>=-180))
w = y;
if ((x>90)||(x<-90)||(y>180)||(y<-180))
System.out.println("Incorrect Latitude or Longitude");
System.out.println("Would you like to enter another location?");
escape = scan.nextInt();
}
System.out.println("Farthest North: " + n);
System.out.println("Farthest South: " + s);
System.out.println("Farthest East: " + e);
System.out.println("Farthest West: " + w);
}
}
This code runs exactly as intended on my personal compiler, Eclipse. However, when running this same program on the course's online compiler, I am met with these errors:
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:322)
at Ideone.assertRegex(Main.java:85)
at Ideone.assertRegex(Main.java:76)
at Ideone.test(Main.java:40)
at Ideone.main(Main.java:29)
What can I do to solve these errors? It seems it's a problem with my Scanner, but I don't know how to fix it.