Question 10
Back to Exercise
What is the output of the following Java program?
public class Main {
public static void main(String[] args) {
StringBuilder sb = new StringBuilder();
outer:
for (int i = 1; i <= 4; i++) {
for (int j = 1; j <= 4; j++) {
if (j > i) continue outer;
if (i * j == 6) break outer;
sb.append(i).append(j).append(' ');
}
}
System.out.println(sb.toString().trim());
}
}
- A 11 21 22 31 Correct
- B 11 21 22 31 32
- C 11 21 22 31 32 33
- D 11 22 33
Correct Answer: Option A
continue outer ends a row as soon as j > i. At i = 3, j = 2 the product is 6 and break outer stops everything.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!