JAVA · ОСНОВЫ · LESSON 09

Two checks.

Знаки && и || · about 15 minutes

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

Both answers should be yes.

&& значит «и». Всё условие верно, только если обе проверки верны.

int age = 9;
boolean canJoin = age >= 7 && age <= 12;

✦ Nine is in the range from 7 to 12.

STEP 2

Enough with one.

| stands for «или». One correct check is enough. Choose a sign according to the meaning of the question.

boolean weekend = day == 6 || day == 7;
Logical signs
&&need both||enough

✦ In Java, two characters == compare values; one = assigns.

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 age = 9;
        boolean canJoin = age >= 7 && age <= 12;
        System.out.println(canJoin);
    }
}
Open the editor for class work
HOMEWORK

Solve it yourself

Create int points = 8. Save boolean passed check: points is not less than 5 and not more than 10. Take out passed.

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

Opening up your homework