public class MathExample {
public static void main(String[] args) {
// TODO Auto-generated method stub
double x = 3.0;
double y = 5.0;
double z = 4.0;
double answer = 0.0;
int a, i;
// y++ is java shorthand for y = y + 1
// ++y is also java shorthand for y = y + 1
// the only difference is when the one is added to y, after or before it is assigned to a variable.
y = 2.0;
System.out.println("y = " + y);
z = y++;
System.out.println("z = y++ now y = " + y + " and z = " + z);
System.out.println("Post Increment, the value of y is assigned to z and THEN y is incremented by 1");
y = 2.0;
System.out.println("y = " + y);
z = ++y;
System.out.println("z = ++y now y = " + y + " and z = " + z);
System.out.println("Pre Increment, the value of y is incremented by one first then assigned to z.");
y = 2.0;
System.out.println("y = " + y);
z = y--;
System.out.println("z = y-- now y = " + y + " and z = " + z);
System.out.println("Post decrement, the value of y is assigned to z and THEN y is decremented by 1");
y = 2.0;
System.out.println("y = " + y);
z = --y;
System.out.println("z = --y now y = " + y + " and z = " + z);
System.out.println("Pre decrement, the value of y is decremented by one first then assigned to z.");
a = 5;
i=++a + ++a + a++;
//i=6 + 7 + 7; (a=8)
System.out.println("i = " + i);
a = 5;
i=a++ + ++a + ++a;
//i=5 + 7 + 8; (a=8)
System.out.println("i = " + i);
}
}