2015-05-10 30 views
-2

我認爲我在某處丟失了括號,但我一直在搜索3個小時,找不到錯誤,也沒有Google搜索幫助我。Java支架問題

我試圖添加結束括號/括號到if語句,但然後我得到了一堆錯誤。一旦有人發現我做了什麼,可能會是一個「唔」的時刻..在此先感謝。

錯誤: NumberGame.java:45:錯誤:文件的最終達成在分析 } ^ NumberGame.java:51:錯誤:文件的最終達成在分析 2個錯誤

import java.util.*; 

public class NumberGame 
{ 
    public static void main(String[] args) 
    { 
     double R = 0; 
     double tryit = 0; 
     double a = 0; 
     double b = 0; 
     while (tryit == 0) 
     { 
      R = 0; 
      while (R != 1) 
      { 
       a = (int)(Math.Random() * 10); 
       b = (int)(Math.Random() * 10); 
       if (a -b >= 0){ 
        R = 1; 
      } 
     } 
     double inpt = -7; 
      while (inpt != (a-b)) 
      { 
       Sytem.out.println("What is " + a + " minus " + b + " ? "); 

       inpt = scanner.inpt = new Scanner(System.in); 

       if ((a -b) == inpt){ 
        System.out.print("Good job, you are correct"); 
        System.out.println("Play again?, Yes or No?:"); 
        String inpt2 = scanner.inpt2 = new Scanner(System.in); 
       if ((a-b) != inpt){ 
        System.out.println("Sorry try again"); 

      } 
     if (inpt2 == "No"){ 
      System.out.println("Thanks for playing"); 
      break; 
     if (inpt2 == "no"){ 
      System.out.println("Thanks for playing"); 
      break; 
    } 
} 
+0

的IDE代表什麼做的?.. – farukdgn

+0

如果你正確地縮進你的代碼,它的格式一致,你會看到errror立竿見影。 – EJP

+0

如果您使用編輯器的自動重新加載功能,那麼添加@ EJP的評論,這將是顯而易見的。 –

回答

0

您的if語句需要右括號:

if (a -b >= 0){ 
    R = 1; 
} 
1

您的if語句需要右括號。

if (a -b >= 0){ 
     R = 1; 
    } // Closing bracket 

    .... 

    if ((a -b) == inpt) { 
     System.out.print("Good job, you are correct"); 
     System.out.println("Play again?, Yes or No?:"); 
     String inpt2 = scanner.inpt2 = new Scanner(System.in); 
    } // Closing bracket 
    if ((a-b) != inpt){ 
     System.out.println("Sorry try again"); 
    } // Closing bracket 

    ... 

    // I think you only need one of these and not two 
    if (inpt2 == "No"){ 
     System.out.println("Thanks for playing"); 
     break; 
    } // Closing bracket 
    if (inpt2 == "no"){ 
     System.out.println("Thanks for playing"); 
     break; 
    } // Closing bracket 
2

if語句左括號,但沒有關閉一個