ADVERTISEMENT
ADVERTISEMENT

Java program to find Square, Cube and Square Root of an integer number

Math.pow() amd Math.sqrt() Methods in Java: In this program, we will take an integer number will find their Square, Cube and Square Root of given number through these methods?

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.
ADVERTISEMENT

Consider the program:

// Java Program to find square, square root 
// and cube of a given number

import java.util.*;

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));
    }
}

Output

Enter an integer number: 12
Square of 12 is: 144.0
Cube of 12 is: 1728.0
Square Root of 12 is: 3.4641016151377544

Java Basic Programs »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.