2015-10-14 88 views
-2

所以我试图找出我的错误是什么,每当我运行这个程序我做了,它不断给我这个错误:错误:异常线程“main” java.util.InputMismatchException

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:452) at Ideone.assertRegex(Main.java:85) at Ideone.assertRegex(Main.java:76) at Ideone.test(Main.java:40) at Ideone.main(Main.java:29)

这是我的代码。

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 lat1 = 0; 
     double long1 = 0; 
     double lat2 = 0; 
     double long2 = 0; 
     double lat3 = 0; 
     double long3 = 0; 
     double lat4 = 0; 
     double long4 = 0; 
     double lat5 = 0; 
     double long5 = 0; 
     double lat6 = 0; 
     double long6 = 0; 
     double lat7 = 0; 
     double long7 = 0; 
     double lat8 = 0; 
     double long8 = 0; 
     double lat9 = 0; 
     double long9 = 0; 
     double lat10 = 0; 
     double long10 = 0; 
     int yesorno = 1; 
     double north = 0; 
     double south = 0; 
     double east = 0; 
     double west = 0; 
     int correct1 = 1; 
     int correct2 = 1; 
     int correct3 = 1; 
     int correct4 = 1; 
     int correct5 = 1; 
     int correct6 = 1; 
     int correct7 = 1; 
     int correct8 = 1; 
     int correct9 = 1; 
     int correct10 = 1; 

    //Run 1 
    if (yesorno == 1) { 
    System.out.println("Please enter the latitide:"); 
    lat1 = scan.nextDouble(); 
    System.out.println("Please enter the longitude"); 
    long1 = scan.nextDouble(); 
    if (long1 >= 180 || long1 <= -180) 
     System.out.println("Incorrect Latitude or Longitude"); 
     correct1 = 0; 
    if (lat1 >= 90 || lat1 <= -90) 
     System.out.println("Incorrect Latitude or Longitude"); 
     correct1 = 0; 
    //Testing for the biggest north south east and west 
    if (long1 > north) 
     north = long1; 
    if (long1 < south) 
     south = long1; 
    if (lat1 > east) 
     east = lat1; 
    if (lat1 < west) 
     west = lat1; 

    System.out.println("Would you like to enter another location?"); 
    yesorno = scan.nextInt(); 
    } 
    //Printing the farthest distances 
    if (yesorno != 1) { 
     if (correct1 == 1) 
      System.out.println("Farthest North: " + north); 
      System.out.println("Farthest South: " + south); 
      System.out.println("Farthest East: " + east); 
      System.out.println("Farthest West: " + west); 
    } 

    //Run 2 
    if (yesorno == 1) { 
     System.out.println("Please enter the latitide:"); 
    lat2 = scan.nextDouble(); 
    System.out.println("Please enter the longitude"); 
    long2 = scan.nextDouble(); 
    if (long2 >= 180 || long2 <= -180) 
     System.out.println("Incorrect Latitude or Longitude"); 
     correct2 = 0; 
    if (lat2 >= 90 || lat2 <= -90) 
     System.out.println("Incorrect Latitude or Longitude"); 
     correct2 = 0; 
    //Testing for the biggest north south east and west 
    if (long2 > north) 
     north = long2; 
    if (long2 < south) 
     south = long2; 
    if (lat2 > east) 
     east = lat2; 
    if (lat2 < west) 
     west = lat2; 

     System.out.println("Would you like to enter another location?"); 
     yesorno = scan.nextInt(); 
    } 
    //Printing the farthest distances 
    if (yesorno != 1) { 
     if (correct2 == 1) 
      System.out.println("Farthest North: " + north); 
      System.out.println("Farthest South: " + south); 
      System.out.println("Farthest East: " + east); 
      System.out.println("Farthest West: " + west); 
    } 

    //Run 3 
    if (yesorno == 1) { 
     System.out.println("Please enter the latitide:"); 
    lat3 = scan.nextDouble(); 
    System.out.println("Please enter the longitude"); 
    long3 = scan.nextDouble(); 
    if (long3 >= 180 || long3 <= -180) 
     System.out.println("Incorrect Latitude or Longitude"); 
     correct3 = 0; 
    if (lat3 >= 90 || lat3 <= -90) 
     System.out.println("Incorrect Latitude or Longitude"); 
     correct3 = 0; 
    //Testing for the biggest north south east and west 
    if (long3 > north) 
     north = long3; 
    if (long3 < south) 
     south = long3; 
    if (lat1 > east) 
     east = lat3; 
    if (lat1 < west) 
     west = lat3; 

    System.out.println("Would you like to enter another location?"); 
    yesorno = scan.nextInt(); 
    } 
    //Printing the farthest distances 
    if (yesorno != 1) { 
     if (correct3 == 1) 
      System.out.println("Farthest North: " + north); 
      System.out.println("Farthest South: " + south); 
      System.out.println("Farthest East: " + east); 
      System.out.println("Farthest West: " + west); 
    } 

    //Run 4 
    if (yesorno == 1) { 
     System.out.println("Please enter the latitide:"); 
    lat4 = scan.nextDouble(); 
    System.out.println("Please enter the longitude"); 
    long4 = scan.nextDouble(); 
    if (long4 >= 180 || long4 <= -180) 
     System.out.println("Incorrect Latitude or Longitude"); 
     correct4 = 0; 
    if (lat4 >= 90 || lat4 <= -90) 
     System.out.println("Incorrect Latitude or Longitude"); 
     correct4 = 0; 
    //Testing for the biggest north south east and west 
    if (long4 > north) 
     north = long4; 
    if (long4 < south) 
     south = long4; 
    if (lat4 > east) 
     east = lat4; 
    if (lat4 < west) 
     west = lat4; 

    System.out.println("Would you like to enter another location?"); 
    yesorno = scan.nextInt(); 
    } 
    //Printing the farthest distances 
    if (yesorno != 1) { 
     if (correct4 == 1) 
     System.out.println("Farthest North: " + north); 
     System.out.println("Farthest South: " + south); 
     System.out.println("Farthest East: " + east); 
     System.out.println("Farthest West: " + west); 
    } 

    //Run 5 
    if (yesorno == 1) { 
     System.out.println("Please enter the latitide:"); 
    lat5 = scan.nextDouble(); 
    System.out.println("Please enter the longitude"); 
    long5 = scan.nextDouble(); 
    if (long5 >= 180 || long5 >= -180) 
     System.out.println("Incorrect Latitude or Longitude"); 
     correct5 = 0; 
    if (lat5 >= 90 || lat5 <= -90) 
     System.out.println("Incorrect Latitude or Longitude"); 
     correct5 = 0; 
    //Testing for the biggest north south east and west 
    if (long5 > north) 
     north = long5; 
    if (long5 < south) 
     south = long5; 
    if (lat5 > east) 
     east = lat5; 
    if (lat5 < west) 
     west = lat5; 

    System.out.println("Would you like to enter another location?"); 
    yesorno = scan.nextInt(); 
    } 
    //Printing the farthest distances 
    //Printing the farthest distances 
    if (yesorno != 1) { 
     if (correct5 == 1) 
      System.out.println("Farthest North: " + north); 
      System.out.println("Farthest South: " + south); 
      System.out.println("Farthest East: " + east); 
      System.out.println("Farthest West: " + west); 
    } 

    //Run 6 
    if (yesorno == 1) { 
     System.out.println("Please enter the latitide:"); 
    lat6 = scan.nextDouble(); 
    System.out.println("Please enter the longitude"); 
    long6 = scan.nextDouble(); 
    if (long6 >= 180 || long6 <= -180) 
     System.out.println("Incorrect Latitude or Longitude"); 
     correct6 = 0; 
    if (lat6 >= 90 || lat6 <= -90) 
     System.out.println("Incorrect Latitude or Longitude"); 
     correct6 = 0; 
    //Testing for the biggest north south east and west 
    if (long6 > north) 
     north = long6; 
    if (long6 < south) 
     south = long6; 
    if (lat6 > east) 
     east = lat6; 
    if (lat6 < west) 
     west = lat6; 

    System.out.println("Would you like to enter another location?"); 
    yesorno = scan.nextInt(); 
    } 
    //Printing the farthest distances 
    if (yesorno != 1) { 
     if (correct6 == 1) 
      System.out.println("Farthest North: " + north); 
      System.out.println("Farthest South: " + south); 
      System.out.println("Farthest East: " + east); 
      System.out.println("Farthest West: " + west); 
     } 
    } 
} 
+0

你需要削减,这归因于[MCVE。具体来说,“最小”的部分。切掉所有多余的东西,找出造成麻烦的线路。 – Teepeemm

回答

0

你对“你想进入另一个位置”的回答是什么? 扫描仪正在等待int“nexInt()”,并且您可能输入了一个字符?

+0

我的回答是1或0回答,1是肯定的,0不是 – TheEpicKiller

0

两种可能性:

  1. 你问一个长期以scan.nextDouble()。尝试:

    long1 = scan.nextLong(); 
    
    scan.nextLine(); 
    
  2. 您输入的整数为

    scan.nextDouble(); 
    
相关问题