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 1 of 2.
Firat said:
1 decade ago
Well, it would be better to ask the output without any missing curly brackets.
Then answer would be i = 0, j = 0, I guess.
Then answer would be i = 0, j = 0, I guess.
Siavash said:
1 decade ago
There is no break; in the second eternity loop, which would make the System. Out. Println an unreachable statement.
Jhon said:
1 decade ago
There is no main method which is to be noticed.
Mehul said:
1 decade ago
If curly brackets would have been there in corrrect pos then answer would be i= 1 and j=0.
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);
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.
Aravindh said:
1 decade ago
What is tp: kindly explain me ?
PleaseBugMeNot said:
1 decade ago
TP represents as label for the loop.
Vishesh said:
1 decade ago
If curly braces of for ended before println then it print i=1 and j=0.
Gaurav said:
1 decade ago
How can j = 0, because when break up run it will print the sop statement.
i.e. i = 1, j = 4.
i.e. i = 1, j = 4.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers