2015-05-18 44 views
0

你們能幫助我完成這個程序嗎?我試圖編譯它,但無法弄清楚它發生了什麼。有兩個java文件,我將發送只有主要問題的文件(直到現在)。這是計算公司每月利潤的簡單程序。.class預期和非法表達

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'預期 對(INT I = 0; INT < catNum;我++){

MonthExe.java:27:錯誤:' 的.class'預期 對(INT J = 1; INT < = curArts; J ++){

MonthExe.java:28:錯誤:」的.class'預期 對(INT K = 1; INT < = curVals.length; k ++){

回答

2

您不能在方法內聲明public變量。刪除關鍵字public

+0

謝謝!我忘了那個! –

2

對於錯誤#1和2,取出public關鍵字,則不能範圍的方法內瓦爾(更here

對於錯誤#3,4,和5所示,在for循環中的第二個表達式聲明需要評估爲布爾值。對於#3 int = catNum應該是這樣的:i < catNum。 #4和5相同。(關於循環here的更多信息)

+0

我將它們中的三個更改爲布爾運算符(如<=和<),並且錯誤仍然存​​在。 –

+0

您是否已將'int'更改爲'i','j'和'k'? –

+0

解決了!謝謝。 –