Java program to take a number as input and calculate the square of that number
Following program shows how to take a number as input and calculate the square of that number.
In this program we get input from user and prints square of that number using following formula
Square of number = input X input
import java.util.Scanner;
public class BasicMath8 {
public static void main(String[] args) {
System.out.println("Please enter a number:");
Scanner in = new Scanner(System.in);
int input = in.nextInt();
int result = input * input;
System.out.println("Squre of " + input + " is: " + result);
}
}
Output:
Please enter a number:
3
Squre of 3 is: 9