我试图在拆分为int后解析字符串。我在打印时收到空值。
public class Usage {
public int[] vectorA, vectorB; public String value;
public String[] valueSplittedA, valueSplittedB;
public void scan(){
Scanner sc = new Scanner(System.in);
value = sc.nextLine();
}
public void scanLine(){ //Get users values for vectors
System.out.println("Enter the first Vector\n");
scan();
valueSplittedA = value.split(" ");
System.out.println("Enter the second Vector\n");
scan();
valueSplittedB = value.split(" ");
for(int i = 0; i<valueSplittedA.length; i++){
String temp = valueSplittedA[i];
vectorA[i] = Integer.parseInt(temp);
}
for(int i = 0; i<valueSplittedB.length; i++){
String temp = valueSplittedB[i];
vectorB[i] = Integer.parseInt(temp);
}
System.out.println(vectorA);
System.out.println(vectorB);
}
}
主要方法:
public class Five {
public static void main(String[] args) {
Usage usage = new Usage();
usage.scanLine();
}
}
两个向量的打印都显示为空。怎么了?