LearnFrenzy
Sign in Take a free test

Control Flow Statements · Predict the Output · Question 8

continue skipping some iterations Answer, explanation & discussion

  • Output
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 8 Back to Exercise

What is the output of the following Java program?

Main.java
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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links