2015-06-30 14 views
0

有人可以幫助我解決我的代碼,使其工作。在控制檯中,它不允許輸入任何內容。有人可以在他們的計算機上測試代碼並向固定代碼發送評論嗎?如果不是,你可以告訴我與我的代碼問題?爲什麼我的輸入掃描儀和我的程序的其餘部分不工作?

String yes =「yes」;

System.out.println("Do you have gym this semester?"); 
    input.nextLine(); 
    if (input.equals(yes)){ 

     int Gym; 
     double GymGpa = 0; 
     System.out.println("Gym = "); 
     Gym= input.nextInt(); 
     input.close(); 
     if (Gym >100){ 
      System.out.println("You have mistyped something"); 
     } 
     if (Gym >= 94 && Gym < 101){ 
      System.out.println("You have an A"); 
      GymGpa = 4.0; 
      System.out.println(GymGpa); 
     } 
     if (Gym < 94 && Gym >=90){ 
      System.out.println("You have an A-"); 
      GymGpa = 3.7; 
      System.out.println(GymGpa); 
     } 
     if (Gym < 90 && Gym >=87){ 
      System.out.println("You have a B+"); 
      GymGpa = 3.3; 
      System.out.println(GymGpa); 
     } 
     if (Gym < 87 && Gym >=80){ 
      System.out.println("You have a B"); 
      GymGpa = 3.0; 
      System.out.println(GymGpa); 
     } 
     if (Gym < 80 && Gym >=77){ 
      System.out.println("You have a B-"); 
      GymGpa = 2.7; 
      System.out.println(GymGpa); 
     } 
     if (Gym < 77 && Gym >=73){ 
      System.out.println("You have a C+"); 
      GymGpa = 2.3; 
      System.out.println(GymGpa); 
     } 
     if (Gym < 73 && Gym >=70){ 
      System.out.println("You have a C"); 
      GymGpa = 2.0; 
      System.out.println(GymGpa); 
     } 
     if (Gym < 70 && Gym >=67){ 
      System.out.println("You have a C-"); 
      GymGpa = 1.7; 
      System.out.println(GymGpa); 
     } 
     if (Gym < 67 && Gym >=67){ 
      System.out.println("You have a D+"); 
      GymGpa = 1.3; 
      System.out.println(GymGpa); 
     } 
     if (Gym < 67 && Gym >=63){ 
      System.out.println("You have a D"); 
      GymGpa = 1.0; 
      System.out.println(GymGpa); 
     } 
     if (Gym < 63 && Gym >=60){ 
      System.out.println("You have a D-"); 
      GymGpa = 0.7; 
      System.out.println(GymGpa); 
     } 
     if (Gym < 60){ 
      System.out.println("You have a F"); 
      GymGpa = 0.0; 
      System.out.println(GymGpa); 
     }//End of Gym 
    }else if (input.equals("no")){ 

    } 
+0

感謝你回答,但不起作用。 –

回答

1

您有String比較一個Scanner。在比較之前,您希望將輸入存儲爲字符串。 試試這個:

... 
Scanner input = new Scanner(System.in); 
String yes = "yes"; 
String answer = input.nextLine(); 

if (answer.equals(yes)){ 
    ... 
} 
+0

感謝您的幫助。我已經創建了一個名爲輸入的代碼的其餘部分的掃描儀。我應該創建一個不同的掃描儀來做到這一點? –

+0

如果您可以重新使用現有的掃描儀,請執行此操作。 – Idva

相關問題