Q:

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

belongs to collection: Java Basic Programs

0

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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Java program to check whether input number is EVEN... >>
<< Java program to find sum and average of two intege...