n 個の数値を入力し、それらを変数に格納して、後で処理できるようにする必要があります。制約: 1. 連続する入力間の任意の数のスペース。2. 入力の数は不明です。3. 入力セットは 256KB を超えてはならず、0<= i <=10^18 の間である必要があります
Example Input:
100
9
81
128
1278
n 個の数値を入力し、それらを変数に格納して、後で処理できるようにする必要があります。制約: 1. 連続する入力間の任意の数のスペース。2. 入力の数は不明です。3. 入力セットは 256KB を超えてはならず、0<= i <=10^18 の間である必要があります
Example Input:
100
9
81
128
1278
あなたの質問を理解できれば、はい。1 つの方法は、 を使用することですScanner
。hasNextDouble()
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);
テキストのように入力がすべて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.
}
}