.class预期和非法表达

时间:2015-05-18 20:39:16

标签: java

你们这些人可以帮我解决这个项目吗?我正在尝试编译它,但无法弄清楚它发生了什么。有两个java文件,我将发送主要的文件,这是有问题的(直到现在)。这是一个计算公司每月利润的简单程序。

import java.util.Scanner;

public class MonthExe{
    public static void main( String[] args ){
        Scanner input = new Scanner( System.in );
        System.out.println( "Inform the current year..." );
        public int curYear = input.nextInt();
        public int catNum;
        String control = "n";
        while ( control = "n" ){
            System.out.println( "Inform the current month..." );
            int curMonth = input.nextInt();
            Month month = new Month( curMonth );
            month.monthMessage( curMonth );
            String control = input.next();
        }
        System.out.println( "Inform the number of arts..." );
        curArts = input.nextInt();
        System.out.println( "Inform the number of categories from the cheapest to the most expensive one..." );
        catNum = input.nextInt();
        curVals = new double[ catNum ];
        for ( int i = 0; int = catNum; i++ ){
            System.out.println( "Inform the price of the category" + ( i + 1 ) );
            curVals[i] = input.nextDouble();
        }
        Month month = new Month( curYear, curArts, curVals );
        for ( int j = 1; int = curArts; j++ ){
            for ( int k = 1; int = curVals.length; k++ ){
                System.out.println( "Inform the amount of units sold for product " + j + " and category " + k );
                int curAmount = input.nextInt();
                month.setProfit( curAmount, k );
                month.setTotalProfit( month.getTotalProfit() );
            }
        }
        month.finalMessage();
        System.out.println( "Thank you for using this software!" );
    }
}

尝试编译上面的程序会给我带来这5个错误...有人可以解释它们的含义吗?提前谢谢!

MonthExe.java:7:错误:非法开始表达                 public int curYear = input.nextInt();

MonthExe.java:8:错误:非法开始表达                 public int catNum;

MonthExe.java:22:错误:'。class'预期                 for(int i = 0; int< catNum; i ++){

MonthExe.java:27:错误:'。class'预期                 for(int j = 1; int< = curArts; j ++){

MonthExe.java:28:错误:'。class'预期                         for(int k = 1; int< = curVals.length; k ++){

2 个答案:

答案 0 :(得分:2)

您无法在方法中声明public个变量。删除关键字public

答案 1 :(得分:2)

对于错误#1和2,请移除public关键字,您不能在方法范围内调整变量(更多here

对于错误#3,4和5,for循环声明中的第二个表达式需要求值为布尔值。对于#3 int = catNum应该是这样的:i < catNum。 #4和5相同。(for循环here更多信息)