← Java from Scratch
Lesson 22 of 88 · 5 XP
Warm-up: the twice method warm-up
Theory and problem statement
Machine translation, not yet reviewed by a native speaker.
A method is a piece of code with a name. For now we write all our methods with the word static inside the Main class:
static int plusOne(int x) {
return x + 1;
}
Calling it from main: plusOne(4) gives 5.
Task. Finish the method twice(int x) that returns the number doubled. main already reads the number and prints twice(n).
Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.