Task 6 of 8 · 0 solved · 8 to go0%
You can read the problem, but answers are checked only for signed-in students. Sign in to answer →

2.1 Selection — building the condition

Lesson

Building the condition

The parentheses of an if hold a boolean — any comparison (> < == !=) or a combination joined with && / ||, just like Module 1's logic.


Worked example

if (score >= 60) { ... }         // a comparison
if (n >= 1 && n <= 10) { ... }   // combined with &&

▶ Try it: run this, then change n — the condition n % 2 == 0 decides even vs odd.



Which condition is true exactly when n is even?


Which condition is true when x is between 1 and 10 inclusive?


Match each condition to when it is true.


Fill the blank so the condition is true exactly when n is negative.


True or false?


Type exactly what this program prints.

public class Main { public static void main(String[] a){
    int n = 12;
    if (n % 2 == 0 && n > 10) {
        System.out.println("big even");
    } else {
        System.out.println("other");
    }
}}