Your First Method
Completed
Complete static int square(int x). The starter reads a number and prints square(n).
Input
One integer.
Output
Its square.
Example
Input
7
Output
49
Editor
Java
Hints
The return type (int) goes before the method name.
return sends the value back to the caller.
Solution explanation
static methods belong to the class, so main can call them directly.
Show solution
import java.util.Scanner;
public class Main {
static int square(int x) {
return x * x;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println(square(sc.nextInt()));
}
}