3. Java Program to find Square and Cube of a given number.
How does this program work?
- In this programme you will learn about how to do Mathematical function using java .
- This programme will helpful to calculate square and cube of a number .
- And then by using the code below you will get output.
Here is the code
//Java Program to find square and cube of a given number.
import java.util.Scanner;public class square
{
public static void main(String args[] )
{
int num;
System.out.print("Enter an integer number:\n");
Scanner obj=new Scanner(System.in );
num=obj.nextInt();
System.out.println("Square of "+ num + " is: "+ Math.pow(num,2));
System.out.println("Cube of "+ num + " is: "+ Math.pow(num, 3));
}
}