Menu
Question Index
...

What will be the output of the following program?

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

        for(int i = 2; i <= 10; i+=2 )
        {
            if( i == 8 ) break;

            sum += i;
        }

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


sum = 18
sum = 36
Compilation error
sum = 12

Doubts

Problems

Topic: Using Break In for Loop To Exit

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App