public class TestOperators { public static void main (String[] argv) { int i = 5; i = i + 1; i += 1; // Shortcut: same as i = i+1; // Pre and post-use increment i = 10; System.out.println (++i); // Prints 10 i = 10; System.out.println (i++); // Prints 11 // Comparison operators: < > <= >= == != int j = 10; if (i != j) System.out.println ("Help! i not equal to l!"); // Casting byte b = 8; long l = 100; i = i + b; // b is automatically converted to an int i = i + l; // Illegal - explicit cast required i = i + (int) l; // OK (explicit downward cast) b = b + 1; // Illegal: `1' is an integer l = l + 1; // OK, `1' is up-cast. b++; // OK, within type. // Bitwise operators: & | ^ << >> >>> &= |= ^= <<= >>= >>>= int x1 = 8, x2 = 15; int x3 = x1 & x2; System.out.println (x3); // What does this print? // Boolean type boolean tired = true; boolean had_enough = true; // Boolean operators: && || ! if (tired && had_enough) System.out.println ("Go home"); } }