Ask a Question
x

Choose Country Code

x

Direction

x

Ask a Question

  • Ask a Question
  • Scan a Question
  • Post MCQ
  • Note: File extension must be of jpg, jpeg, png, bmp format and file size must not exceed 5 MB
x

Ask a Question

x

Hire a Tutor

Answers and Solutions

What's Your Question?
Answer

package test; import java.util.Scanner; public class SquareRoot

{

    public static void main(String args[])

 {                //Used to get input number for which square root to find         Scanner scanner = new Scanner(System.in);         System.out.println("Enter number to find square root in Java : ");         //getting input number from user to calculate square root         double square = scanner.nextDouble();         //getting square root of a number in Java         double squareRoot = Math.sqrt(square);                //printing number and its square root in Java         System.out.printf("Square root of number: %f is : %f %n" , square, squareRoot);         } } Output: Enter number to find square root in Java :64 Square root of number: 64.000000 is : 8.000000

Answer

package test; import java.util.Scanner; /**  *  * Java program to find square root of number in Java.  * This Java program example demonstrate using Math class  * sqrt() method to get square root of a number in Java.    */ public class SquareRoot

{     public static void main(String args[])

 {                //Used to get input number for which square root to find         Scanner scanner = new Scanner(System.in);                System.out.println("Enter number to find square root in Java : ");                //getting input number from user to calculate square root         double square = scanner.nextDouble();                       //getting square root of a number in Java         double squareRoot = Math.sqrt(square);                //printing number and its square root in Java         System.out.printf("Square root of number: %f is : %f %n" , square, squareRoot);          }       } Output: Enter number to find square root in Java :64 Square root of number: 64.000000 is : 8.000000

Answer
Math.sqrt(number); Example: System.out.print(Math.sqrt(25));// output is 5.0 and remember Math class returns double data type.
Answer

You can simply use the function Math.sqrt(n);

If you want complete program, see following link:

https://www.careerbless.com/samplecodes/java/beginners/basicprograms/SquareRootDemo.php

Post Answer and Earn Credit Points

Get 5 credit points for each correct answer. The best one gets 25 in all.

Post Answer