JAVA · ОСНОВЫ · LESSON 17

Give me the word.

Argument of method · about 14 minutes

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

The method receives a gift

Between the brackets of the method, you can specify the input: type and name. So the method gets different words.

static void greet(String name) {
    System.out.println("Привет, " + name);
}

✦ name is the word that was conveyed when called.

STEP 2

Call me with a word.

Put the text in the call brackets. One method can welcome different people.

greet("Маша");

✦ «Привет, Маша» will appear.

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) {
        greet("Маша");
    }
    static void greet(String name) {
        System.out.println("Привет, " + name);
    }
}
Open the editor for class work
HOMEWORK

Solve it yourself

Make static void greet(ZString name), which outputs «Здравствуй, » and name. In main, call greet for «Аня».

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

Opening up your homework