gpt4 book ai didi

java - 类中的方法不能应用于给定类型(java)

转载 作者:行者123 更新时间:2023-12-01 18:43:58 25 4
gpt4 key购买 nike

我试图在我的主方法中使用另一个类的方法,但出现错误。它告诉我类中的方法不能应用于给定类型。

public class studentclass {
public void inputloop(String[] args){

Scanner scan = new Scanner(System.in);
String[][] student = new String[10][];
Double[][] results = new Double[10][];
Double[] total = new Double[10];


String tableln = "";

for(int index = 0; index < student.length; index++){
System.out.println("\nPlease enter student " + (index+1) + "'s details");
String userinput = scan.nextLine();
student[index] = userinput.split(",");
results[index] = new Double[4];

results[index][0] = Double.parseDouble(student[index][2]);
results[index][1] = Double.parseDouble(student[index][3]);
results[index][2] = Double.parseDouble(student[index][4]);
results[index][3] = Double.parseDouble(student[index][5]);
total[index] = (results[index][0]*0.1+results[index][1]*0.4+
results[index][2]*0.2+results[index][3]*0.3);

System.out.println("\nStudent name\tFAN \t\tResult1\tResult2\tResult3\tResult4\tTotal");
tableln = tableln + "\n" + student[index][0] + "\t" + student[index][1] + "\t"
+ results[index][0] + "\t" + results[index][1] + "\t" + results[index][2] + "\t"
+ results[index][3] + "\t" + total[index];
System.out.println(tableln);
}
}

然后在我的主要方法中输入此内容。

    public static void main(String[] args) {
studentclass info = new studentclass();
info.inputloop();
}

它说“studentclass 类中的方法 inputloop 无法应用于给定类型。required String[] 未发现任何争论。”请帮我。谢谢

最佳答案

您的方法的签名是:

public void inputloop(String[] args)

您应该将字符串数组传递给该方法:

info.inputloop(someStringArray);

参见this欲了解更多信息:

The parameter list in parenthesis—a comma-delimited list of input parameters, preceded by their data types, enclosed by parentheses, (). If there are no parameters, you must use empty parentheses.

我没有看到您正在使用此参数,因此您只需将方法签名更改为

public void inputloop()

现在这将是一个有效的调用,就像您所做的那样。

关于java - 类中的方法不能应用于给定类型(java),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18681391/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com