Menu
Topics Index
...
`

dowhile and break statement


If you need explanation Read this topic

If you need Answer Take test on this topic

dowhile and break statement
What will be the output of the following program?
public class DoingWhile {
    public static void main(String[] args) {
        int i = 18;
        System.out.print('a');
        outer : while (3 < 4) {
            System.out.print('b');
            do {
                System.out.print('c');
                if (i++ > 20)
                    break outer;
                if (1 < 2)
                    break;
                System.out.print('d');
            } while (6 > 7);
            System.out.print('e');
        }
        System.out.print('f');
    }
}

A. ababbabbabbaf
B. abcebcebcebcf
C. abecbecbecbef
D. Some other output
E. Compilation Error or Runtime Error
Topic: Using break In Nested Loop Java Program

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.

b

Posted by Datta Sai Krishna    2013-08-26 09:44:54


ans is b: 1st a will be printed , as 3<4 b will be printed , as its do while, it doesn't check the condition for the 1st time so 'c' will be printed...as 1<2 is true come out of do while...again ebc will be printed until i++>20...atlast f will be printed

Posted by Sulekha Metta    2013-08-26 09:45:21


Ans is B.. first 'a' printed , 3<4 so 'b', 'c', 1<2 =true break so 'e',next 'b','c','e' when i++>20 statemnt becomes true outer vl be terminated from loop finally 'f' printed.. so ans is abcebcebcebcf...

Posted by Om Prakash Om    2013-08-26 10:04:31


ans b:

Posted by Sravan Haram    2013-08-26 12:08:12


Congratulations Om Prakash Om. You are this dose winner. Please send us your mobile details in a private message and we will process the recharge asap.

Posted by Merit Campus    2013-08-27 03:47:12


Thank u MC:)

Posted by Om Prakash Om    2013-08-27 09:36:22


© meritcampus 2019

All Rights Reserved.

Open In App