unary operator ( –num etc )
private static void postPreEntuware() { int x1 = -1; //System.out.println("initially x1 = "+x1); int x2 = x1--; //System.out.println("now (x1--) x1 = "+x1); int x3 = ++x2; if(x2 > x3) { --x3; } else { x1++; --x3; } int answer = x1 + x2 + x3; System.out.println("answer = "+answer); }
Loops
remember the 3rd operand is like last line of the loop ( e.g. for(int i=0; i<10; ++i )
so i++ , ++i make no difference in this case as the loop is effectively:
for(int i=0; i<10; ++i ){ do something ... ++i; }
v. important – the loop increment is always the the last thing to happen, before the next turn of the loop
Assignment
Loop with break and continue
Below will not compile ( in ** Class ** even abstract, abstract method MUST be marked abstract )
abstract class Automobile{ void honk(); }