Ads

Java program to find sqare,cube and square root of a given number | JAVA LANGUAGE | JAVA PROGRAMMING

 Given an integer number and we have to find their Square, Square Root and Cube.

In this program, we are using these two methods of Math class:

1.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).

2.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));

}

}



Post a Comment

0 Comments