我知道這裏存在很多問題,但我做了所有這些解決方案,但仍然無法正常工作。出於某種原因,只存儲第一輸入將字符串數組轉換爲雙數組
我輸入:
1
2
3
4
預期輸出:
[1.0,2.0,3.0,4.0]
實際輸出:
[1.0]
代碼
inputValue = stdin.readLine(); //Reads input
String [] input = inputValue.split ("\\R");
double [] numbers = new double[input.length];
for(int i = 0; i < input.length; i++){
numbers[i] = Double.parseDouble(input[i]);}
爲什麼你把它看作一個字符串,你可以直接讀取值作爲'double'並直接放入數組中。不需要額外的'String'變量。 –