×

java · level 1 · unit 7 · lesson 2

  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

A is a slot where your method catches information.

Picture your method as a machine. Right now it does the same thing every time. Cut a slot in the front, and you can feed in something new on each go.

That slot is a parameter: a box in the method's brackets, with a type and a name, like String name in static void greet(String name). Inside the method, use it like any other box.

The value you drop in when you call is the . Call greet("Mia") and name holds "Mia". Call greet("Leo") and the same machine greets Leo instead.

public class Main {
    static void greet(String name) {
        System.out.println("Hello, " + name + "!");
    }
    public static void main(String[] args) {
        greet("Mia");
        greet("Leo");
    }
}

Need two slots? Split the parameters with commas, and the arguments too.