当我运行for循环时,第5行中的语句第一次被忽略。但是第二次和第三次执行。
public void scanStrings() {
String[] stringsArray = new String[3];
for (int i = 0; i < 3; i++) {
System.out.println("Give me the phrase no. " + (i+1));
stringsArray[i] = scan.nextLine(); // it is ignored in the 1st loop???
}
}
预期结果将是:
Give me the phrase no. 1
(1st string scan)
Give me the phrase no. 2
(2nd string scan)
Give me the phrase no. 3
(3rd string scan)
我得到的实际结果是:
Give me the phrase no. 1
Give me the phrase no. 2
(2nd string scan)
Give me the phrase no. 3
(3rd string scan)