| preferred AP College board partner for AP classes
medium Solved by 3 students
Nested Loop With Break Statement
< Prev
Next >

What is printed when the following program is executed?

public class NestedBreak {
    public static void main(String[] args) {
        int count = 0;
        for (int i = 0; i < 3; i++){
            for (int j = 0; j < 5; j++){
                if(j == 2)
                    break;
                count++;
            }
        }
        System.out.println(count);
    }
}
A

6

B

9

C

3

D

5

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer

Question Leaderboard

Not enough data yet to show leaderboard.

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy