Menu
Question Index
...

What will be the output of the following program?

class NestedForloop
{
    public static void main(String s[])
    {
        int sum = 5;        
        int i = 1;
        for( ; i <= 4; )
        {
            for(int j = 1; j <= 4; j++ )
            {
                sum += (i * j);
                i++;
            }
        }
        System.out.println("Sum = " + sum);
    }
}


Sum = 35
Sum = 51
Sum = 19
Compilation Error
Runtime Error

Doubts

Problems

Topic: Nested for Loop In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App