如何将扫描仪输入放入数组中...例如,几个数字
2022-09-02 00:50:48
Scanner scan = new Scanner(System.in);
double numbers = scan.nextDouble();
double[] avg =..????
Scanner scan = new Scanner(System.in);
double numbers = scan.nextDouble();
double[] avg =..????
你可以尝试这样的事情:
public static void main (String[] args)
{
Scanner input = new Scanner(System.in);
double[] numbers = new double[5];
for (int i = 0; i < numbers.length; i++)
{
System.out.println("Please enter number");
numbers[i] = input.nextDouble();
}
}
这似乎是很基本的东西,除非我误解了你
您可以使用以下代码获得所有双精度:
List<Double> numbers = new ArrayList<Double>();
while (scan.hasNextDouble()) {
numbers.add(scan.nextDouble());
}