in this tutorial, we will learn how to calculate the square of a number in a Java
Example:
package javaapplication;
import java.util.Scanner;
/**
* @author Rathorji
*/
public class JavaApplication {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num;
System.out.print("Enter an integer number: ");
num = sc.nextInt();
System.out.println("Square of " + num + " is: " + Math.pow(num, 2));
}
}
output:
run:
Enter an integer number: 144 Square of 144 is: 20736.0 |