class FromLeftToRight {
// Here H stands for famous physicist WERNER HEISENBERG(1901-1976)
// Even Heisenberg Uncertainty Principle does not apply here!
// Adding or substracting zeroH() will NOT affect your result
// Multiplying or Dividing oneH() will NOT affect your result
// These are the secrets of measuring your system without disturbing the system
public static int zeroH(
String s, int n) {
System.out.println(s + ": " + n);
return 0;
}
public static int oneH(String s, int n) {
System.out.println(s + ": " + n);
return 1;
}
public static void main(String arg[]) {
System.out.println("//*****************");
System.out.println("int x = 0;");
System.out.println("x = x++; ");
int x = 0;
// adding 0's will not affect the result
// x = x++; The equivalent statment of the following
x = zeroH("Initial", x) + x++ + zeroH("Before assignment", x);
zeroH("After assignment", x);
System.out.println("//*****************");
System.out.println("int y = 5;");
System.out.println("y = y++ + y++;");
int y = 5;
// adding 0's will not affect the result
//y = y++ + y++; The equivalent statment of the following
y = zeroH("Initial", y) + y++ + zeroH("In the middle", y) + y++ + zeroH("Before assignment", y);
zeroH("After assignment", y);
System.out.println("//*****************");
System.out.println("int z = 5;");
System.out.println("z = z++ * z++;");
int z = 5;
// multiplying 1's will not affect the result
//z = z++ * z++; The equivalent statment of the following
z = oneH("Initial", z) * z++ * oneH("In the middle", z) * z++ * oneH("Before assignment", z);
zeroH("After assignment", z);
System.out.println("//*****************");
}
}
// The output
//*****************
int x = 0;
x = x++;
Initial: 0
Before assignment: 1
After assignment: 0
//*****************
int y = 5;
y = y++ + y++;
Initial: 5
In the middle: 6
Before assignment: 7
After assignment: 11
//*****************
int z = 5;
z = z++ * z++;
Initial: 5
In the middle: 6
Before assignment: 7
After assignment: 30
//*****************