JAVA · ОСНОВЫ · LESSON 02

A number with a name

int and addition · about 12 minutes

Learning with progressRead the summary for free. To save the work, log in to the account.
STEP 1

Integer box

int says Java: There will be an integer. Then give the box a name and put the number in the sign.

int apples = 4;

✦ The name apples now stores 4.

STEP 2

Count and show.

Java can count to the right of =. In println, pass the name of the box without quotation marks: you will see the answer, not its name.

int apples = 2 + 3;
System.out.println(apples);
Addition
2 + 3believeapplesstore 5printlnshow 5

✦ The result is 5.

IN-CLASS PRACTICE

Type the code yourself

Type the program manually. Compare the sign = and the sign +.

public class Main {
    public static void main(String[] args) {
        int stars = 2 + 4;
        System.out.println(stars);
    }
}
Open the editor for class work
HOMEWORK

Solve it yourself

Inside main, create an integer a as the sum of 1 and 1. Deduce the value of a.

The answer is hidden. Use similar examples from the lesson notes.

Opening up your homework