Java Learner logo
← Back to all exercises

Control Flow

Flow control with break/continue

What single number reaches System.out.println at the end?

Control Flow

Flow control with break/continue

IntermediateAwaiting attempt

What single number reaches System.out.println at the end?

public class Main {
    public static void main(String[] args) {
        int[] numbers = {3, 9, 12, 15, 18};
        int total = 0;

        for (int number : numbers) {
            if (number % 2 == 0) {
                continue;
            }
            total += number;
            if (total > 20) {
                break;
            }
        }

        System.out.println(total);
    }
}