Angela
Originally posted by Angela Narain:
Consider the below example :
public class test
{
public static void main( String[] args )
{
int i = 3;
System.out.println(i *=2 + i++);
}
}
Here is what is happening:
The equation would be evaluated like this,
i = i * (2 + i++)
The first thing the compiler does is evaluate the value of all of the operands, in this case it is only i. Because it a postfix expression it has no effect on i until after the expression is evaluated so i is 3. Now it will start to solve the expressions.
i = 3 * (2 + 3)
i = 3 * 5
i = 15
The value of 15 is assigned to i. Even if you tried to print the value of i in a line afterwards it will still print 15, because the value of the expression is assigned back into i after the increment is done.
Look at this code here. If we use a nother variable to hold the value of the expression then i will be incremented as we expect.
If that didn't help let me know...
------------------
Dave
Sun Certified Programmer for the Java� 2 Platform