Originally posted by Raji Addepalli:
public class TeSet {
public static void main(String args[]) {
int m = 2;
int p = 1;
int t = 0;
for(;p < 5;p++) {
if(t++ > m) {
m = p + t;
}
}
System.out.println("t equals " + t);
}
}
for this output is t equals 4.
Can any body explain how it is?
Raji,
This Qs put some variable statement here & there to blur your sight, actually if you look more closely, you will see, we are asked to predict the value of t.
And inside the code, the only place t will get updated is "t++" in if (t++>m), since this if statement is part a for loop that will repaet 4 times. p=1,2,3,4.
t++ encounted 4 times, so t =4.