GCGrowCarrer

Operators and Expressions

Locked

Lesson 2 of 60 · Syntax · Easy

Finish these first:Variables and Primitive Types →Or pass the tests below to unlock it now.

1

The big idea

Operators let Java add, subtract, multiply, and divide numbers right inside your code. Java calculates the right side of = first, then puts the answer into the variable on the left: Remember to put the type (int) before the variable name and finish the line with a semicolon ;.

Think of it like this: Think of operators like calculator keys (`+`, `-`, `*`, `/`) that turn two numbers into one result before storing it in your variable.
Key words (tap to learn):
2

Read the lesson

Operators let Java add, subtract, multiply, and divide numbers right inside your code.

Java calculates the right side of = first, then puts the answer into the variable on the left:

int apples = 3 + 5;    // 8
int change = 10 - 4;   // 6
int area = 3 * 4;      // 12
int half = 10 / 2;     // 5

Remember to put the type (int) before the variable name and finish the line with a semicolon ;.

3

Quick check

What value is stored in `sum` after running `int sum = 3 + 5;`?

4

Your challenge

1 sample test, 1 hidden

Inside Solution, create an int variable named total that adds 4 and 6 (type int total = 4 + 6;).

Stuck? Get a hint (free)
More learning tools(compare languages, visual guide, related lessons)

Compare with another language

Similar to python.operators (90% overlap). `/` is true division in Python but integer division on ints in Java; use `//` vs `/`.

Visual walkthrough

A diagram, a step-by-step animation, and short captions for Operators and Expressions.

Mastery0%