Jan 10, 2003 #1 engdict Programmer Jan 8, 2003 10 US The following code outputs 2, not 3. Any insight as to why would be very useful. (The corresponding code in C++ outputs 3) int i = 2; i = i++; System.out.println(i); TIA.
The following code outputs 2, not 3. Any insight as to why would be very useful. (The corresponding code in C++ outputs 3) int i = 2; i = i++; System.out.println(i); TIA.
Jan 11, 2003 #2 scoon Programmer Apr 2, 2002 32 US java does not handle prefix and postfix the same way that other lang's do. in java, prefix will change the value of the variable but postfix will not. int i = 2; i = i++; System.out.println("i: " + i); will give the output of 3. hope this helps. Upvote 0 Downvote
java does not handle prefix and postfix the same way that other lang's do. in java, prefix will change the value of the variable but postfix will not. int i = 2; i = i++; System.out.println("i: " + i); will give the output of 3. hope this helps.
Jan 31, 2003 #3 userinfo IS-IT--Management Dec 4, 2002 40 US both prefix and postfix will increase the variable by one. however, whether the "++" is near of far from the "=" acts differently. j=i++ meane j=i j=++i means j=(i+1) in other words, if "++" is near "=", then it counts. otherwise, it does not affect the initialization value of "j". Upvote 0 Downvote
both prefix and postfix will increase the variable by one. however, whether the "++" is near of far from the "=" acts differently. j=i++ meane j=i j=++i means j=(i+1) in other words, if "++" is near "=", then it counts. otherwise, it does not affect the initialization value of "j".