Write the output of the following program segment:

ICSE Class 10 Computer Applications PYQ · 2025 Improvement · Section A

2(iv)1 Mark · 2025 · Section A · 2025 Improvement

Write the output of the following program segment:

for(int a = 1; a <= 10; a++) 
{ 
if(a % 2 == 0) 
continue; 
System.out.print(a + "  "); 
}
Show SolutionHide Solution↓
1  3  5  7  9
  1. The loop control variable a is initialized to 1 and is incremented by 1 after each iteration until it attains the value 10.
  2. The condition if (a % 2 == 0) tests whether a is an even number. If the condition is true, the continue statement transfers control to the next iteration of the loop, thereby skipping the print statement.
  3. Consequently, only the odd values 1, 3, 5, 7, and 9 are displayed by the statement System.out.print(a + " ");.
← Previous questionNext question →

Share on WhatsApp

Browse the free Computer Applications sample bank