2013-10-20 15 views
0

我有一個具有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 
+1

多少個參數是你傳遞? –

+0

你怎麼稱呼這個方法? – ankit

+0

我在調用方法中有4個整數參數,但只需要傳遞一個,但我猜java不能這樣工作。我只想給System.out.print一個參數,不是全部4. – user2899341

回答

2

你的方法與 整數參數

定義

但在您的方法調用中,您僅傳遞 參數,這是不正確的。你需要通過 整數參數

這是錯誤的:calcpoints(final_points)

這是正確的(例如):calcpoints(1,2,3,4)

+0

謝謝。我必須在return語句中編寫所有參數嗎?例如:return(1,2,3,4)。我掙扎着,因爲我只想在system.out.println語句中返回一個參數。 – user2899341

+0

@ user2899341:方法代碼沒有錯。順便解決方法調用,你沒有發佈。 – afk5min

+0

我的調用方法是System.out.println(「Your score - >」+ calcpoints(total_points); – user2899341