JAVA · ОСНОВЫ · LESSON 12

row of numbers

int array[edit] · about 14 minutes

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

One box for many

The array stores several values of one type. int is a series of integers. The brackets hold the numbers themselves.

int[] scores = {3, 5, 7};

✦ There are three numbers in the array.

STEP 2

Show me the number.

The array has length — how many values are inside. Write it after the dot without parentheses.

int[] scores = {3, 5, 7};
System.out.println(scores.length);
A row
3place5seat72nd

✦ The result is 3.

IN-CLASS PRACTICE

Type the code yourself

Type an example manually. Check the signs and brackets.

public class Main {
    public static void main(String[] args) {
        int[] scores = {3, 5, 7};
        System.out.println(scores.length);
    }
}
Open the editor for class work
HOMEWORK

Solve it yourself

Create an int[] array called numbers with 2, 4, 6, 8. Print its length using length.

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

Opening up your homework