Menu
Question Index
...

What will be the output of the following program?

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

        int count = 10;

        while( n <= 3 )
        {
            sum += (n * 2);

            if( count < 7 )
            {
                break;
            }
            count--;
            n++;
        }

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


sum = 6
sum = 12
Goes into infinite loop
sum = 14

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