Agree what Miga said. 2009/8/14 miga <[email protected]>
> > > > On Aug 14, 8:11 am, siva prasad <[email protected]> wrote: > > 1. public class TestOR { > > 2. public static void main( String[] args ){ > > 3. int i = 0; > > 4. int j = 10; > > 5. boolean test= false; > > 6. //demonstrate || > > 7. System.out.println(j++);//10 > > 8. test = (i < 10) | (j++ > 9);//11 > > 9. System.out.println(i); > > 10. System.out.println(j++);//12 > > 11. System.out.println(j++);//13 > > 12. System.out.println(test); > > 13. //demonstrate | > > 14. test = (i < 10) || (j++ > 9);//14 > > 15. System.out.println(i); > > 16. //System.out.println(j);//1 > > 17. System.out.println(j);//14 > > 18. System.out.println(j++);//14 > > 19. System.out.println(test); > > 20. } > > 21. } > > > > O/p: > > > > 10 > > 0 > > 12 > > 13 > > true > > 0 > > 14 > > 14 > > true > > > > I couldnt understand y the value of j didnt change in the lines 17 & 18 > of > > the above program. > The operator ++ when using after the variable (aka j++) is applied > after the method when it is used. That is in: > System.out.println(j++); it first display the current value of j, then > increment the value of j. > Use ++j if you want to increment first and then use the newly > incremented value in the method where you call it: > System.out.println(++j); > > > --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/javaprogrammingwithpassion?hl=en -~----------~----~----~----~------~----~------~--~---
