Menu
Coddy logo textTech

Arithmetic Shortcuts

Part of the Fundamentals section of Coddy's Java journey — lesson 19 of 73.

Java created a cool shortcut for self-arithmetic operations.

For example instead of writing:

int a = 5;
a = a + 3; // a holds 8

We can simplify it by writing +=:

int a = 5;
a += 3; // a holds 8

The += is adding to a itself the value 3

This operation is valid for all arithmetic operations:

OperatorShortcut
++=
--=
**=
//=
%%=
challenge icon

Challenge

Beginner

You are given a code with initialization of count. (Don't delete this line!)

Your task is to add the following operations, in this order:

  1. Add 4 to count
  2. Multiply count by 2
  3. Subtract 1 from count

Use the arithmetic shortcuts to do so!

Cheat sheet

Java provides shortcut operators for self-arithmetic operations:

OperatorShortcut
++=
--=
**=
//=
%%=

Instead of writing:

int a = 5;
a = a + 3; // a holds 8

You can use the shortcut:

int a = 5;
a += 3; // a holds 8

Try it yourself

public class Main {
    public static void main(String[] args) {
        int count = 0;
        
        // Type your code below
        
        
        // Don't change the line below
        System.out.println("count = " + count);
    }
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals