class Foozit { public static void main(String[] args) { Integer x = 0; Integer y = 0; for(Short z = 0; z < 5; z++) if((++x > 2) || (++y > 2)) x++; System.out.println(x + " " + y); } } i think there is syntax error as they have not opened the curly brackets.....for for loop please help me..............
As said in the earlier post - If a for isn't followed by braces, it loops the statement that follows the for. In this case "If" is the looped statement.
Here we are looping 5 times and each time values of X and Y are: x y 0 - 1 1 1 - 2 2 2 - 4 2 (As the first expr is evaluated as TRUE, second expr won't executed) 3 - 6 2 (As the first expr is evaluated as TRUE, second expr won't executed) 4 - 8 2 (As the first expr is evaluated as TRUE, second expr won't executed)
If a for isn't followed by braces, it loops the statement that follows the for. In this case "If" is the looped statement.
thanks a lot..........i am preparing for scjp and having many problems........so i just take chance to post my problem and in returned i got many mails and now my problem is solved....... hope you will help me in future also.........
Where does a nanny get ground to air missles? Protect this tiny ad: