×

java · level 1 · unit 4 · lesson 3

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

adds more paths to the fork.

Some questions have more than two answers. else if adds another condition to check when the ones above it were false. Java checks from the top down and runs only the first block whose condition is true.

Every gives true or false. < means less than, > more than, <= less than or equal to, >= more than or equal to, and != not equal to.

Text is different. To compare strings, use , like pet.equals("cat"). == asks whether two strings are the very same box, not the same letters, so it can say false when the text matches.

public class Main {
    public static void main(String[] args) {
        int temperature = 12;
        String pet = "cat";
        if (temperature < 5) {
            System.out.println("Wear a big coat.");
        } else if (temperature < 15) {
            System.out.println("A jumper will do.");
        }
        System.out.println(pet.equals("cat"));
    }
}

In <= and >= the = always comes second, never first.