在第一个循环中,该语句似乎被忽略了

时间:2019-04-25 09:40:56

标签: java arrays for-loop

当我运行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)

0 个答案:

没有答案
相关问题