我是一个绝对的初学者。 我知道如何用“if”找到最大值,但我想用一种方法来做。问题是我怎样才能保留最后一个Max的记录!如何编写一个JAVA方法来查找最大用户输入?
public class Max
{
public static double Max (double score){
double max = 0;
if (score > max)
max = score;
return max;
}
public static void main (String [] arg){
Scanner scan = new Scanner (System.in);
double score = 0;
do{
System.out.print("Enter the scores (-1 to end input) > ");
score = scan.nextDouble();
}while (score >= 0);
System.out.println("Highest score: " + Max(score));
}
}
不要忘记,以纪念我的回答是接受 – Developer