For Loop Termination Condition
The intended behavior is to print numbers 1 through 10, but “10” is never printed. What is the error in the loop?
public class PrintNumbers {
public static void main(String[] args) {
for (int i = 1; i < 10; i++) {
if(i == 10)
System.out.print("10");
else
System.out.print(i + " ");
}
}
}
A
The if condition inside the loop wrongly tests for i equal to 10.
B
The loop variable i is not correctly declared within the loop.
C
The print statement should use println instead of print.
D
The loop condition should be i <= 10 instead of i < 10.
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE