【发布时间】:2013-10-20 04:54:34
【问题描述】:
我有一个具有 4 个 int 值的 nonvoid 方法,但我只想“返回”其中一个 int 值。我在调用“calcpoints(final_points)”的语句中收到一条错误消息(如下)。
需要错误:int,int,int,int 发现:int 原因:实际参数列表和形式参数列表的长度不同
我的代码:
public static int calcpoints (int points, int total_points, int answer, int correct) {
while ((points >= 0) && (answer != correct)) {
System.out.println("Display problem");
answer = GetInput.readLineInt();
if (answer == correct) {
total_points = total_points + points;
} else {
points = points / 2;
}
total_points = total_points + points;
}//end of while loop points
return (total_points);
}//end of the calculate points method
【问题讨论】:
-
你传递了多少个参数?
-
你是怎么调用这个方法的?
-
我在调用方法中有4个整数参数,但只需要传递一个,但我猜java不是这样工作的。我只想 System.out.print 一个参数,而不是全部 4 个。