-2

n 個の数値を入力し、それらを変数に格納して、後で処理できるようにする必要があります。制約: 1. 連続する入力間の任意の数のスペース。2. 入力の数は不明です。3. 入力セットは 256KB を超えてはならず、0<= i <=10^18 の間である必要があります

Example Input: 
100
                  9 
        81
                              128
1278
4

2 に答える 2

2

あなたの質問を理解できれば、はい。1 つの方法は、 を使用することですScannerhasNextDouble()

Scanner scan = new Scanner(System.in);
List<Double> al = new ArrayList<>();
while (scan.hasNextDouble()) { // <-- when no more doubles, the loop will stop.
  al.add(scan.nextDouble());
}
System.out.println(al);
于 2014-09-12T17:11:40.177 に答える
0

テキストのように入力がすべて1行で行われる場合は、次のようにすることができます。

import java.util.ArrayList;

public class Numbers 
{
    public static void main(String[] args) 
    {
        ArrayList<Double> numbers = new ArrayList<Double>();
        String[] inputs = args[0].split(" ");

        for (String input : inputs)
        {
            numbers.add(Double.parseDouble(input));
        }
        //do something clever with numbers array list.
    }
}
于 2014-09-12T17:15:11.610 に答える