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.
Example:
Sample Input:5
Square root of 5= 2.2360679
Rounded Form= 2
Cube root of 5= 1.7099759
Rounded form= 2
Floor value of 2.2360679 =2.0
Ceil value of 2.2360679 =2.0
Answers
Answer:
First-order reactions are very common. We have already encountered two examples of first-order reactions: the hydrolysis of aspirin and the reaction of t-butyl bromide with water to give t-butanol. Another reaction that exhibits apparent first-order kinetics is the hydrolysis of the anticancer drug cisplatin.
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