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.
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.
Mehul said:
1 decade ago
If curly brackets would have been there in corrrect pos then answer would be i= 1 and j=0.
Vishesh said:
1 decade ago
If curly braces of for ended before println then it print i=1 and j=0.
Jhon said:
1 decade ago
There is no main method which is to be noticed.
PleaseBugMeNot said:
1 decade ago
TP represents as label for the loop.
Aravindh said:
1 decade ago
What is tp: kindly explain me ?
Vikas said:
10 years ago
What is tp doing with break?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers