有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

Java为多个值中的一个调用非类方法

我有一个具有4个int值的非OID方法,但我只想“返回”这些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

共 (1) 个答案

  1. # 1 楼答案

    您的方法由4整数参数

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

    但在方法调用中,只传递1参数,这是不对的。您需要传递4整数参数

    这是错误的:calcpoints(final_points)

    这是正确的(例如):calcpoints(1,2,3,4)