Accenture Java Programming Practice Question
Predict the output. public class Test { public static void main(String args[]) { int a = 2, b = 0; for ( ; b < 20; ++b) { if (b % a == 0) continue; else if (b == 10) break; else System.out.print(b + " "); } } }Answer options
A
1 3 5 7 9 11 13 15 17 19
B
Code executes but gives no output
C
0 2 4 6 8
D
Compile-time error
Correct answer: 1 3 5 7 9 11 13 15 17 19
Explanation
The loop skips even values using continue. The break condition b == 10 is never reached because 10 is even and continue executes first, so all odd values from 1 to 19 are printed.