0

I have a nonvoid method with 4 int values, but i only want to "return" just one of those int values. I get an error message (below) in the statement where i call "calcpoints(final_points).

ERROR required: int,int,int,int found: int reason: actual and formal argument lists differ in length

my code:

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
3
  • 1
    How many arguments are you passing in? Oct 20, 2013 at 4:56
  • how are you calling this method ?
    – ankit
    Oct 20, 2013 at 5:03
  • i have 4 integer parameters in the call method, but only need to pass just one, but i guess java doesn't work that way. i only want to System.out.print one parameter, not all 4. Oct 20, 2013 at 5:54

1 Answer 1

2

Your method is defined with 4 Integer parameters

public static int calcpoints (int points, int total_points, int answer, int correct)
{

}

But in your method call, you are passing only 1 parameter, which is not right. You need to pass 4 Integer parameters

This is wrong: calcpoints(final_points)

This is right(for example): calcpoints(1,2,3,4)

4
  • Thanks. do i have to code all the parameters in the return statement? example: return (1, 2, 3, 4). i'm struggling because i only want to return one parameter in a system.out.println statement. Oct 20, 2013 at 5:43
  • @user2899341: the method code is not at fault. Fix the method call, which you did not post, by the way.
    – Tadas S
    Oct 20, 2013 at 5:50
  • my call method is System.out.println("Your score --> " + calcpoints(total_points); Oct 20, 2013 at 5:51
  • Passing and Returning are two different things. While passing parameters to a method, you need to adhere to method definition. If your method definition has 4 parameters defined, you have to pass 4 parameters. As far as returning is concerned, you can only return scalar(single) value. Oct 20, 2013 at 9:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.