Computer Science, asked by UtkarshChawhan, 4 months ago

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 anubhav6083
0

Answer:

import java.util.*;

class First_Help

{

   void main()

   {

       Scanner sc = new Scanner(System.in);

       System.out.println("Enter a number");

       double n = sc.nextInt();

       double sq = Math.sqrt(n);

       double sqfl = Math.floor(sq);

       double sqce = Math.ceil(sq);

       double cb = Math.cbrt(n);

       System.out.println("The floor value of the square root of the number is "+sqfl);

       System.out.println("The ceil value of the square root of the number is "+sqce);

       System.out.println("The cube root  of the number is "+cb);

   }

}

Explanation:

Please take the number input as double type only because Math functions do no support any other data types

Answered by Oreki
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