我需要从这段代码中获得最大值,但这真的很麻烦。有人有什么建议吗?
import java.util.Scanner;
public class Test{
public static void main(String args[])
{
Scanner scan = new Scanner(System.in);
final int sentinel = 0;
int number;
int maxval = 0;
int count = 0;
System.out.println ("Enter a number: ");
number = scan.nextInt();
while (number != sentinel)
{
count++;
System.out.println("Enter another number");
number = scan.nextInt();
maxval = number;
}
if (number > maxval)
{
maxval = number;
System.out.println ("The max value is " + maxval);
}
}
}