×

java · level 1 · unit 3 · lesson 1

  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

Quotes turn a number into text.

5 is a number. "5" in quotes is a string that happens to look like one, and Java treats them very differently. 5 + 3 adds up to 8, but "5" + "3" joins into 53.

Join a string and a number and the number becomes text too, so "Apples: " + 5 gives Apples: 5. Whole numbers go in int boxes. Numbers with a decimal point, like 0.75, go in boxes.

Each box only takes its own type. Put text in an int box and Java stops with , which means the value does not fit the label.

public class Main {
    public static void main(String[] args) {
        int apples = 5;
        double price = 0.75;
        System.out.println(5 + 3);
        System.out.println("5" + "3");
        System.out.println("Apples: " + apples);
        System.out.println(price);
    }
}

Put 2 in a double box and it shows as 2.0, with its decimal point.