我試圖在java中輸入字符串。我輸入應該是這樣的Java從控制檯輸入字符串輸入
3
1,1,[email protected],123 Sesame St.,New York,NY,10011,12345689010
1,2,[email protected],123 Sesame St.,New York,NY,10011,12345689010
1,3,[email protected],123 Sesame St.,New York,NY,10011,12345689010
所以,我想這
Scanner in = new Scanner(System.in);
int TotalNumber = in.nextInt();
String[] Data = new String[TotalNumber];
for (int Counter = 0; Counter < TotalNumber; Counter++) {
Data[Counter] = in.next();
}
in.close();
for (int counter = 0; counter < Data.length; counter++) {
System.out.println(Data[counter]);
}
我的輸出顯示這個
1,1,[email protected],123
Sesame
St.,New
什麼是我的問題嗎?如何正確輸入字符串行?
更新
,我發現我的解決方案在這裏Scanner issue when using nextLine after nextXXX
我嘗試nextLine()3 1,1,錯誤@ bunny.com,123芝麻街,紐約,紐約州,10011,12345689010 1,1,錯誤@ bunny.com,123 Sesame St.,紐約,紐約州,10011,12345689010它只需要我輸入2個輸入 –
是否適合你? – user12458
@JavaTechnical no –