Write a Java program to input a number. Calculate its square root and cube root. Finally, display the result by rounding it off. Also display the floor and ceil values of the Square root of the number entered by the user
Answers
Answered by
2
Code:
import java.util.Scanner;
public class CubeSquareRoots {
public static void main(String[ ] args) {
System.out.print("Enter a number - ");
int number = new Scanner(System.in).nextInt( );
double squareRoot = Math.sqrt(number),
cubeRoot = Math.cbrt(number);
System.out.println("Square Root - " + Math.round(squareRoot));
System.out.println(" Ceil - " + Math.ceil(squareRoot));
System.out.println(" Floor - " + Math.floor(squareRoot));
System.out.println("Cube Root - " + Math.round(cubeRoot));
}
}
Sample I/O:
Enter a number - 123
Square Root - 11
Ceil - 12.0
Floor - 11.0
Cube Root - 5
Similar questions
Psychology,
2 months ago
Social Sciences,
2 months ago
English,
2 months ago
Hindi,
4 months ago
Math,
4 months ago
English,
10 months ago
Math,
10 months ago