Question 8
Back to Exercise
What is the output of the following Java program?
public class Main {
public static void main(String[] args) {
int sum = 0;
for (int i = 1; i <= 10; i++) {
if (i % 2 == 0) continue;
if (i == 7) continue;
sum += i;
}
System.out.println(sum);
}
}
- A 18 Correct
- B 25
- C 55
- D 16
Correct Answer: Option A
Odd numbers 1 + 3 + 5 + 9 = 18 (7 is skipped too).
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!