Write a program in Java to display square and cube of a number.
Answers
In this program, we are using these two methods of Math class:
Math.pow(m,n):
It is used to get the power of any base, it will return m to the power of n (m^n).
Math.sqrt(m):
It is used to get the square root of any number, it will return square root of m.
import java.util.*;
/*Java Program to find square, square root and cube of a given number*/
public class j5
{
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));
System.out.println("Cube of "+ num + " is: "+ Math.pow(num, 3));
System.out.println("Square Root of "+ num + " is: "+ Math.sqrt(num));
}
}
hola mate
here is ur answer
hope this helps
❤❤❤❤❤