package expressions;

public class AugmentedAssignOps {
    public static void main(String[] args) {

        /*
         * Augmented Assignment Operators:
         * You already know about the assignment operator =
         * You can use augmented assignment operators as a shortcut
         * for certain combinations of mathematical operations.
         * 
         * += Addition Assignment
         * -= Subtraction Assignment
         * *= Multiplication Assignment
         * /= Division Assignment
         * %= Modulus Assignment
         */

        int x = 1;
        x += 2; // x is now 3
        System.out.println(x);
        x -= 1; // x is now 2
        System.out.println(x);
        x *= 5; // x is now 10
        System.out.println(x);
        x /= 2; // x is now 5
        System.out.println(x);
        x %= 2; // x is now 1
        System.out.println(x);

        /*
         * Note that these only work when the variable has been
         * initialized: this won't work:
         */
        // int y;
        // y += 5;
    }
}
