Menu
Question Index
...

What will be the output of the following program?

class ContinueExample
{
    public static void main(String s[])
    {
        int sum = 0;

        for(int i = 2; i <= 10; i++ )
        {
            if( i % 3 == 0 ) continue;

            if( i == 8 ) break;

            sum += i;
        }

        System.out.println("sum = " + sum);
    }
}


sum = 18
sum = 36
Compilation error since continue and break can not be used in the same for loop.
sum = 27

Doubts

Problems

Topic: Java continue Statement

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App