MCQ
Single Best Answer
Moderate
QGive the output of the following code:
for (i = 5; i >= 1; i--) {
if (i % 2 == 1)
continue;
System.out.println(i + " ");
}
ID: #23878
ICSE Computer Application - Class X - Selection Examination - 2024-25 - MCQ - CALCUTTA PUBLIC SCHOOL
76 views
Question Info
#23878Q ID
ModerateDifficulty
ICSE Computer Application - Class X - Selection Examination - 2024-25 - MCQ - CALCUTTA PUBLIC SCHOOLTopic
Your Answer
Choose the Best Option
Click any option to instantly check if you're correct.
Correct Answer: Option A
Explanation
Output of the Following Code
for (i = 5; i >= 1; i--) {
if (i % 2 == 1)
continue;
System.out.println(i + " ");
}
Explanation
The loop starts from 5 and decreases up to 1.
The condition:
i % 2 == 1
checks whether the number is odd.
If the number is odd, the continue statement skips the remaining part of the loop.
So, only even numbers are printed.
Step-by-Step Execution
i = 5 → odd → skipped
i = 4 → even → printed
i = 3 → odd → skipped
i = 2 → even → printed
i = 1 → odd → skipped
Output
4
2 Continue Practice
Share
Share This Question
Challenge a friend or share with your study group.
More from This Topic