0

When I run the for loop, the statement in 5th line is ignored the 1st time. But the 2nd and 3rd time it is executed.

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???
    }
}

The expected result would be:

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)

The actual result I take is:

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 Answers0