Menu
Topics Index
...
`

Do while output820


If you need explanation Read this topic

If you need Answer Take test on this topic

Do while output820
What will be the output of the program?
class Output
{
    public static void main(String [] args)
    {
        int I = 1;
        do while ( I < 1 )

                System.out.print("I is " + I);

        while ( I > 1 ) ;
    }
}

A. I is 1
B. I is 1 I is 1
C. No output is produced
D. Compilation error
Topic: do while 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.

C. no output produed. As in first loop- do gets executed then in second loop I<1 which is false so SOP line is not executed. Now do-while condition I>1 which is also wrong. So no output is produced and program gets terminated

Posted by Ankur Verma    2014-10-14 12:07:40


Answer : C nothing will get printed as none of the while conditions are satisfied as I==1

Posted by Deepak Kumar Yadav    2014-10-14 12:08:29


ans is C as in first do while(I<1) condition is checked as it is false it comes out of loop   and for next  condition i>1 condition is false and no output is produced

Posted by Ramya Reddy Addulla    2014-10-14 12:16:03


C

Posted by Jayakrishna Nani    2014-10-14 12:23:45


c

Posted by Shubham Bansal    2014-10-14 12:51:16


Ans is C..here we create an Local varible I and initilized with 1

here we have 2 loops..while and Do while..

while wil check condtion for every iteration where as do while wil check evry time except 1st time..do while wil useful while creating options to user

when we didnt write {} for loops  only 1st statement after the loop wil consider into the loop..
when we have 1 statemetns {} is optional

in do while condtion is I<1 which is false so that the SOP wont get executed.
next we have while loop with 1 statment so {} optional..
here also Contion is false so no output...

in both loops if contion is true than it wil becm infinite loop

Posted by Uday Kumar    2014-10-14 13:28:16


C .in output class I is initialized to 1.  In do while loop first time execute without checking condition and then checks the condition. in while condition fails so print statement will not execute and in second while loop also condition.

Posted by Ananthoju Arun Chary    2014-10-14 14:30:19


This dose is now closed and the winners are Ankur Verma,  for 'First Correct Comment', Uday Kumar,  for 'Best Comment' and Šâí Râm for the 'Popular Comment'. The 'lucky liker' is Ananthoju Arun Chary. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.

Posted by Merit Campus    2014-10-15 03:45:39


c

Posted by Arul Palanisamy    2014-10-15 03:50:22


© meritcampus 2019

All Rights Reserved.

Open In App