Java Programming - Flow Control - Discussion
Discussion Forum : Flow Control - Finding the output (Q.No. 8)
8.
What will be the output of the program?
public class Test
{
public static void main(String [] args)
{
int I = 1;
do while ( I < 1 )
System.out.print("I is " + I);
while ( I > 1 ) ;
}
}
Answer: Option
Explanation:
There are two different looping constructs in this problem. The first is a do-while loop and the second is a while loop, nested inside the do-while. The body of the do-while is only a single statement-brackets are not needed. You are assured that the while expression will be evaluated at least once, followed by an evaluation of the do-while expression. Both expressions are false and no output is produced.
Discussion:
14 comments Page 2 of 2.
Jaics said:
1 decade ago
while ( I < 1 )
System.out.print("I is " + I)
They form two statements, how can they be a single statement...So curly bracket is required..right?
System.out.print("I is " + I)
They form two statements, how can they be a single statement...So curly bracket is required..right?
Srikar said:
1 decade ago
More clarified equivalent of above program is:
do
{
while(i<1)
{
System.out.....;
}
}
while(i>1);
do
{
while(i<1)
{
System.out.....;
}
}
while(i>1);
Ashi said:
1 decade ago
I guess there is a syntax error.
Pawan said:
2 decades ago
Is do-while syntax correct? guess not.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers