2015-09-27 55 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

相关问题