Related questions with answers
Question
After the break statement in (a) is executed in the following loop, which statement is executed? Show the output. After the continue statement in (b) is executed in the following loop, which statement is executed? Show the output.
a.
for(int i = 1; i < 4; i++) {
for(int j = 1; j < 4; j++) {
if(i * j > 2)
break;
System.out.println(i * j);
}
System.out.println(i);
}
b.
for(int i = 1; i < 4; i++) {
for(int j = 1; j < 4; j++) {
if(i * j > 2)
continue;
System.out.println(i * j);
}
System.out.println(i);
}
Solution
VerifiedAnswered 1 year ago
Answered 1 year ago
Step 1
1 of 2Case A: the break statement will be followed by the last println statement that outputs the .
Case B: the continue statement is followed by the .
The output is in both cases: 1 (i = 1, j = 1, 1 * 1) 2 (i = 1, j = 2, 1 * 2) 1 (i = 1) 2 (i = 2, j = 1, 2 * 1) 2 (i = 2) 3 (i = 3)
Create an account to view solutions
By signing up, you accept Quizlet's Terms of Service and Privacy Policy
Create an account to view solutions
By signing up, you accept Quizlet's Terms of Service and Privacy Policy
More related questions
1/4
1/7