Menu
Topics Index
...
`

Print I value


If you need explanation Read this topic

If you need Answer Take test on this topic

Print I value
What will be the output of the following program?
public class MastiBrother {
    public static void main(String[] args) {
        int i = 5;
        while (i < 7) {
            for (int k = 0; k < 2; k++) {
                System.out.print(i);
            }
            i++;
        }
    }
}

A. 5566
B. 5656
C. Some other output
D. Compilation Error
E. Runtime Error
Topic: Nested Loops 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.

Ans A; Loop prints normally

Posted by Uday Kumar    2014-01-13 15:07:53


ans is A ...intially i=5 as 5<7 enters while loop and as k<2 i is printed twice , now i is incremented i=6 now, 6<7 so enters while loop and i is printed 2s as k<2 , now i=7 as 7<7 is flase it wont enter while loop.

Posted by Sulekha Metta    2014-01-13 15:10:08


C. Output 56

Posted by Kishan Viru    2014-01-13 15:14:12


ans A

Posted by Koka Raga Salini    2014-01-13 15:53:54


A is ans. initially i is 5 enters while satisfying for loop two times prints 5 5 now i is incrmntd ie 6.. again enters while satisfing for loop prints 6 6 so ans is 5566

Posted by Shabaaz Shaikz    2014-01-13 16:22:58


i=5 then condition is true then ' i ' printed 5 5  then for terminated ' i ' incremented  i=6 then while is true then ' i ' printed 6 6 finally answer 5566.

Posted by Siva Kumar Sudarsi    2014-01-14 06:22:30


Congratulations Sulekha Metta. You are this dose winner. We will send you a link using which you can claim your recharge.

Posted by Merit Campus    2014-01-14 07:43:43


A

Posted by Shravan Kumar    2014-01-16 15:37:57


© meritcampus 2019

All Rights Reserved.

Open In App