2013-11-21 73 views
0

這是什麼問題,我得到一個錯誤,指出:解析時到達文件結尾。我該如何解決這個問題? 我曾嘗試沒有結果在解析時到達文件結尾,

public class FindMin 
{ 
public static void main(String[] args) 
{ 
    Scanner keyboard = new Scanner(System.in); 

    int smallest = 9999999; 
    String userInput; 
    boolean quit = false; 

    System.out.println("This program finds the smallest number" 
     + " in a series of numbers"); 
    System.out.println("When you want to exit, type Q"); 

    while(quit != true) 
    { 
     System.out.print("Enter a number: "); 
     userInput = keyboard.next(); 
     if(userInput.equals("Q")) userInput.equals("q"); 
     { 
      if(quit == true) { 

} 

      else    

      { 

      int userNumber = Integer.parseInt(userInput); 

      if(UserNumber < smallest) 
       smallest = userNumber; 
     } 
    } 
    System.out.println("The smallest number is " + smallest); 
    System.exit(0); 

} 

回答

0

這只是太亂了幾個東西,試試這個

import java.util.Scanner; 
public class FindMin{ 
public static void main(String[] args){ 
    Scanner keyboard = new Scanner(System.in); 

    int smallest = 9999999; 
    String userInput; 
    boolean quit = false; 

    System.out.println("This program finds the smallest number" 
     + " in a series of numbers"); 
    System.out.println("When you want to exit, type Q"); 

    while(true) 
    { 
     System.out.print("Enter a number: "); 
     userInput = keyboard.next(); 
     if(userInput.equalsIgnoreCase("q")) 
       break; 
     else{ 
      int userNumber = Integer.parseInt(userInput); 
      if(userNumber < smallest) 
       smallest = userNumber; 
     } 
    } 
    System.out.println("The smallest number is " + smallest); 
} 
} 
+0

最後完成編輯:) – JoeC

+0

沒有工作,IM仍然得到同樣的錯誤 – user3015774

+0

你確定你使用的是最新的版本?只是複製整個塊並更換主塊再次 我只是想,這裏是輸出 '如果你想退出該程序發現在一系列數字 的最小數量,Q型 輸入一個數字:5 輸入一個數字:6 輸入一個數字:4 輸入一個數字:7 輸入一個數字:● 最小的號碼是4' – JoeC

0

檢查括號:他們不匹配,這就是爲什麼編譯器會抱怨:

FindMin.java:35: reached end of file while parsing 

此外,還有一個錯字和該程序的其他問題。見其他答案以供參考:)

相關問題