Menu
Topics Index
...
`

Water


If you need explanation Read this topic

Water
What will be the output of the following program?
public class WaterInWater {
    public static void main(String[] args) {
        boolean water = true;
        while (water) {
            System.out.println(water);
            while (water) {
                water = false;
                System.out.println(water);
            }
        }
        System.out.println(water);
    }
}

A. true
false
true
B. true
false
false
C. true
true
true
D. Compilation Error
E. Runtime Error
Topic: Nested While Loop In Java

If you need explanation Read this topic

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

Ans is b..initialy water is true so true wil print nxt it entering into inner while loop so the water became false n printg so loop wil terminaterd n out side we are printg so it wil print  false

Posted by Uday Kumar    2014-06-27 03:34:01


Answer is B,
as Explained by Uday Kumar.

Posted by Amar Kumar Biradar    2014-06-27 04:08:14


B

Posted by Shri Nandhitha    2014-06-27 04:28:36


B

Posted by Rishav Seksaria    2014-06-27 05:40:16


B   first water is having true then after entering  into the loop it becomes false

Posted by Aparna Lakshmi    2014-06-27 07:18:23


so it prints true then false false

Posted by Aparna Lakshmi    2014-06-27 07:18:59


b

Posted by Rutvik Gosalia    2014-06-27 08:17:57


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

Posted by Merit Campus    2014-06-30 05:17:05


© meritcampus 2019

All Rights Reserved.

Open In App