A

Admin • 828.03K Points
Coach

Q. What is the output of the following code?

Code:
for (int i = 1; i <= 10; i++) {
if (i % 2 == 0) {
continue;
}
System.out.println(i);
}
  • (A) 1 3 5 7 9
  • (B) 2 4 6 8 10
  • (C) 1 2 3 4 5 6 7 8 9 10
  • (D) There is a syntax error in the code.
  • Correct Answer - Option(A)
  • Views: 14
  • Filed under category Java
  • Hashtags:

Explanation by: Admin
The for loop iterates from 1 to 10, skipping any even numbers using the continue statement. The odd numbers are printed to the console.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.