你能帮我解决这个程序吗?我正在尝试编译它,但无法弄清楚它发生了什么 . 有两个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'预期为(int i = 0; int <catNum; i){
MonthExe.java:27:错误:' . class'预期为(int j = 1; int <= curArts; j){
MonthExe.java:28:错误:' . class'预期为(int k = 1; int <= curVals.length; k){
2 回答
对于错误#1和2,删除
public
关键字,您不能在方法内调整范围(更多here)对于错误#3,4和5,for循环声明中的第二个表达式需要求值为布尔值 . 对于#3
int = catNum
应该是这样的:i < catNum
. #4和5相同 . (for循环的更多信息here)您不能在方法中声明
public
变量 . 删除关键字public
.