write a java program to
read a number via the scanner class and display its square, cube, square root and cube root
Answers
Explanation:
// 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));
}
}
Mark me as Brainliest
my whatsApp 7390030157
Answer:
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:
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.
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