为什么无法调用类,运行提示"
Syntax error on token 'new'"
标点符号没有问题,求指教.
import java.util.Scanner;
class Cal {
int couple;
int number,temp;
int calculation(int year){
number = 0;
if(year%2 == 0){couple = year / 2;}
else {couple = (year - 1)/2;}
for(int i = 0; i < couple; i++){
temp = (1 + year - 1 - 1 * i) * (year - 1 - 1 * i) / 2 + 1;
number = number + temp;
}
return number;
}
}
public class rabit {
public static void main(String[] args) {
int year_n;
System.out.println("Please enter a number of months:");
Scanner input = new Scanner(System.in);
year_n = input.nextInt();
Cal mm = new Cal;
int year = mm.calculation(year_n);
System.out.println("The rabbit number is : " + year );
}
}
------解决方案--------------------Cal mm = new Cal;
这一行改成 Cal mm = new Cal();
------解决方案--------------------规则,必须遵守。