gpt4 book ai didi

java - 我在最后一行 "cannot find symbol"之一中收到错误

转载 作者:行者123 更新时间:2023-11-30 03:25:22 26 4
gpt4 key购买 nike

我不断收到错误消息,说找不到该符号,我已经查看过,但不知道哪里出了问题。它将打印一个包含用户输入的数字的数组,然后从那里找出他们输入的最大数字是多少。

class Soutar_maximumvalue{

public static void main (String[] args){
//Welcome
System.out.println ("Welcome to Matthew's program to find the maximum number.");

max();

//Goodbye
System.out.println ("Thank you for using my program.");
}

public static void max(){
//Variable Declaration
double userinput1, userinput2, userinput3, userinput4, userinput5;
double [] max;
Scanner First = new Scanner(System.in);
//Input
System.out.println ("Please enter your first number.");
userinput1 = First.nextDouble();
System.out.println ("Please enter your second number.");
userinput2 = First.nextDouble();
System.out.println ("Please enter your third number.");
userinput3 = First.nextDouble();
System.out.println ("Please enter your fourth number.");
userinput4 = First.nextDouble();
System.out.println ("Please enter your fifth number.");
userinput5 = First.nextDouble();

max = new double [5];
max[0] = userinput1;
max[1] = userinput2;
max[2] = userinput3;
max[3] = userinput4;
max[4] = userinput5;
System.out.println( Arrays.toString( max ) );

System.out.println (Math.max(userinput1,userinput2,userinput3,userinput4,userinput5)); // This is the line with the error
}
}

最佳答案

Math.max 在 java 中不是可变参数。它需要两个参数

解决方案是更换

Math.max(userinput1,userinput2,userinput3,userinput4,userinput5)

Collections.max(Arrays.asList(max))

感谢您刚刚创建的数组。

关于java - 我在最后一行 "cannot find symbol"之一中收到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30351542/

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