enter image description here一旦我进入列表。它不会显示最大值。我试图在最后一个println中调用max,但它仍然无效。
ArrayList<Double> numbers = new ArrayList<Double>();
Scanner keyboard = new Scanner(System.in);
System.out.println("Please enter a list of numbers: ");
while (keyboard.hasNextDouble())
{
double input = keyboard.nextDouble();
numbers.add(input);
}
Double max = Collections.max(numbers);
System.out.println("The Maximum is: " );
}}
答案 0 :(得分:1)
怎么样
修改强>
// check to make sure that numbers has some elements
if (numbers.size () <= 0) {
// some message
return;
}
Double max = Collections.max(numbers);
System.out.println("The Maximum is: " + max );
// ^^^^^^
答案 1 :(得分:0)
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
ArrayList<Double> numbers = new ArrayList<Double>();
Scanner keyboard = new Scanner(System.in);
System.out.println("Please enter a list of numbers: ");
while (keyboard.hasNextDouble()) {
double input = keyboard.nextDouble();
numbers.add(input);
if (input == -99)
break;
}
Double max = Collections.max(numbers);
System.out.println("The Maximum is: " + max); // you have missed to add max here
}
}
休息会帮助你。
Please enter a list of numbers:
2
3
13
4
-99
The Maximum is: 13.0
输出:
find . -type d | sort | xargs -n1 -I{} bash -c "find {} -type f -maxdepth 1 -executable | sort -r"
答案 2 :(得分:0)