2015-09-27 56 views
-1

我工作的一個項目,詢問他們想購買該房用戶和我得到幾個錯誤說「表達的非法啓動」在我的每個方法的開始階段,我總是收到表達式非法開始的錯誤,這是什麼錯誤?

import java.util.Scanner; //Utility to take inputs from keyboard 

public class RentingLab 
{ 

    public static void main (String args[]) //main method 
    { 
     //code in the main method 
    } 



    { 
    do //start of do while loop 

     if (option == 3) //if the user decides to select third option for housing purchase 
     { 

      public static double price(double rentingPrice) //where the error for illegal start of expression is occurring 
      { 
      //code in the method 
      } 

     } 
    //then more methods done in a similar fashion with "else if" statements 
    while (option !=0); 
    } 
    } 

回答

0

首先您的循環必須我在你的主要方法。您只能在主方法之外創建方法。這意味着public static double price(double rentingPrice)必須在您的主要方法之外。我建議你遵循一些教程。

+0

如果我的do-while循環在我的主要方法中,我應該如何在我的do-while循環中使用我的方法?我的其他方法目前在主要方法之外。 –

+0

您需要查看一個類的基本結構。這應該引導您以正確的方式組織代碼,例如在您的班級的第一級定義的所有方法。使所有的行爲(如do語句)發生在主要方法內部。 – subdigit

相關問題