public int rangeInScanner(Scanner stream) {
int max = stream.nextInt();
int min = stream.nextInt();
while (stream.hasNextInt()){
if (stream.nextInt() > max) {
max = stream.nextInt();
}
if (stream.nextInt() < min) {
min = stream.nextInt();
}
}
return max - min;
}
为什么我不能让它工作。假设 Scanner stream = new Scanner("5, 4, 3, 2, 1"); 我希望这个返回 4。