There is this simple program which has loops and jump statement. I am unable to figure out the output that it is giving.
public class Breaker2{
static String o = "";
public static void main(String[] args) {
z:
for(int x = 2; x < 7; x++) {
//System.out.println(o + " x is this : " + x);
if(x==3) continue;
if(x==5) break z;
o = o + x; //2nd question is about this piece of code
}
System.out.println(o);
}
}
I am having the following doubts, Sorry if someone finds them simple or silly.
1. Why cannot I place a Print statement immediately after the jump label (z:)
- How is it able to convert from int to string and add/contact the x variable
- I see that the output 24 comes only by concatenating the values of x. Is it the right conclusion?