Menu
Topics Index
...
`

NestedFor loop


If you need explanation Read this topic

If you need Answer Take test on this topic

NestedFor loop
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; )
            {
                for(int k = 1; k < 4 - 1; k++)
                {
                    sum *= (i * j);
    
                    i++;
                    j++;
                    k++;
                }
            }
        }
        System.out.println("Sum = " + sum);
    }
}

A. Sum = 2880
B. Sum = 576
C. Sum = 180
D. Compilation Error
E. Runtime Error
Topic: Nested for Loop In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

run time error

Posted by Aruna Dantu    2014-03-31 05:38:58


Ans is C..simple multiplications...

Posted by Uday Kumar    2014-03-31 05:39:35


ans is C

Posted by Adithya Aleti    2014-03-31 05:40:33


c is the ans here we multiply the i and j values 2 times insider the inner most loop for the iteration of the outer 2 loops.

Posted by Karteek Paruchuri    2014-03-31 05:44:37


Congratulations Karteek Paruchuri. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-04-01 05:08:53


© meritcampus 2019

All Rights Reserved.

Open In App