Java Programming - Flow Control - Discussion
Discussion Forum : Flow Control - Finding the output (Q.No. 20)
20.
What will be the output of the program?
int i = 0, j = 5;
tp: for (;;)
{
i++;
for (;;)
{
if(i > --j)
{
break tp;
}
}
System.out.println("i =" + i + ", j = " + j);
Answer: Option
Explanation:
If you examine the code carefully you will notice a missing curly bracket at the end of the code, this would cause the code to fail.
Discussion:
17 comments Page 2 of 2.
PleaseBugMeNot said:
1 decade ago
TP represents as label for the loop.
Aravindh said:
1 decade ago
What is tp: kindly explain me ?
Alex said:
1 decade ago
If compilation fails for the lack of the ending curly brace, compilation would fail for the lack of a main function. These questions imply the code snippets are just that - snippets - and so it would be perfectly reasonable to assume there is a curly brace later on in the code but not included in the snippet. That doesn't change the fact that the print statement is unreachable though.
Ghogale said:
1 decade ago
No, I run that program it give error unreachable statement at
System.out.println("i =" + i + ", j = " + j);
System.out.println("i =" + i + ", j = " + j);
Mehul said:
1 decade ago
If curly brackets would have been there in corrrect pos then answer would be i= 1 and j=0.
Jhon said:
1 decade ago
There is no main method which is to be noticed.
Siavash said:
1 decade ago
There is no break; in the second eternity loop, which would make the System. Out. Println an unreachable statement.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers