我有一個具有4個int值的nonvoid方法,但我只想「返回」其中的一個int值。我得到的聲明(見下文)的錯誤信息,其中我稱之爲「calcpoints(final_points)對於一個值的Java調用nonvoid方法很多
ERROR要求: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
多少個參數是你傳遞? –
你怎麼稱呼這個方法? – ankit
我在調用方法中有4個整數參數,但只需要傳遞一個,但我猜java不能這樣工作。我只想給System.out.print一個參數,不是全部4. – user2899341