我已经从标准输入接受了一个输入。这个输入将是一个数字的一行。例如,对于变线的有效值为:在一条线上读取数字
1 2 3 4 5 6 7 8 9 10
我知道有多少数字会有,我已经存储在这个变量N.我想这些数字存储大小的数组N.
String a="";
for(int i=0; i<line.length(); i++){
if(line.charAt(i)!=' ')
a = a+ line.charAt(i);
else{
numbers[x++]=Integer.parseInt(a);
a="";
}
}
numbers[x]=Integer.parseInt(a); //to store the last number in the array
有没有更有效的方法呢?