2013-10-09 25 views
0

再次我需要幫助關於Java編程.. 我試圖使通過是/否是聽命的方法..但似乎我得到一個錯誤:「非法啓動表達」和‘錯誤‘’預計’遷移到另一種方法

如果用戶輸入是/是的,它會移動到方法MainProgram(主程序) 如果用戶輸入不,它會再見打印,並將退出 ,如果用戶輸入一邊從是/否會再次詢問,直到滿足條件

請幫助我真的需要這個..是的是學校的相關。這其實是程序的一半,告訴我是否需要整個程序。謝謝!

import java.io.*; 

public class Testing{ 
    public static void main (String args[])throws IOException{ 

    String p; 
    final String proc="Yes"; 
    final String decl="No"; 

     System.out.print("Do you want to proceed? - Yes/No"); 
     p=inpt.readLine(); 

     for(int i=1; i<=1; i++){ 
      if (p.equalsIgnoreCase(proc)){ 
      MainProgram(); 
      } else if (p.equalsIgnoreCase(decl)){ 
        System.out.println("Goodbye!"); 
      System.exit(0); 
      } else 
      System.out.println("Wrong Input"); 
      System.out.println(); 
      i=i-1; 
      continue; 
      } 

     public void MainProgram(){ 
      System.out.println("How many sets of students' grades would you like to record?"); 
      System.out.print("Answer: "); 
      rec = Integer.parseInt(inpt.readLine()); 
      System.out.println(); 
+0

當你問一個關於Java編程你一定要添加【JAVA]標籤問題該鏈接將幫助你在未來,如果現在不http://thenewboston.org/list.php?cat=31 – DogCoffee

+0

。 – Pavlo

+0

噢,我很抱歉.. – user2768501

回答

0

你只是缺少一個右{

試試這個。

for(int i=1; i<=1; i++) 
{ 
if (p.equalsIgnoreCase(proc)) 
{ 
    MainProgram(); 
} 
else if (p.equalsIgnoreCase(decl)) 
{ 
System.out.println("Goodbye!"); 
    System.exit(0); 
} 
else { 
    System.out.println("Wrong Input"); 
    System.out.println(); 
    i=i-1; 
    continue; 
} 
} 
+0

對不起,但它使很多錯誤xD – user2768501

0

移動你的方法MainProgram()main()之外。

您不能在其他方法中定義方法,至少不能在Java中定義方法。 :)

+0

看來,該方法是一個錯誤的不循環.. awrgh – user2768501

+0

@ user2768501:我已經更新了我的答案。 – user278064