JAVA · ОСНОВЫ · LESSON 16

Your command.

Method without argument · about 14 minutes

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

Name the action.

The method is an action with a name. Write it inside the Main class, but outside of main. The word void means that the method does not return the answer.

static void wave() {
    System.out.println("Привет!");
}

✦ The method is ready, but it's silent.

STEP 2

Call the method.

Inside main, write the method name with brackets. Then his action will be carried out.

wave();
Command
wavenamewave()challengeПривет!result

✦ The method will show a greeting.

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) {
        wave();
    }
    static void wave() {
        System.out.println("Привет!");
    }
}
Open the editor for class work
HOMEWORK

Solve it yourself

Create static void cheer(), which outputs «Ура!». Call cheer from main.

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

Opening up your homework