Table of Contents
In this tutorial. we will see if how to get square root of number in java.
It is very simple to get square root of number in java. You can simply use Math’s sqrt() method to calculate square root of number.
Syntax
1 2 3 |
double sqrt(double d) |
Return type
It returns square root of the number.
Square root of number
Let’s see sqrt method with the help of example.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
import java.math.*; package org.arpit.java2blog; public class SquareRootMain { public static void main(String[] args) { double d1=26.0; System.out.println("Square root of 26:"+Math.sqrt(d1)); double d2=56.0; System.out.println("Square root of 56:"+Math.sqrt(d2)); double d3=83.0; System.out.println("Square root of 83:"+Math.sqrt(d3)); } } |
Above program will generate below output.
Square root of 26:5.0990195135927845
Square root of 26:7.483314773547883
Square root of 26:9.1104335791443
Square root of 26:7.483314773547883
Square root of 26:9.1104335791443
That’s all about square root of number in java
Was this post helpful?
Let us know if this post was helpful. Feedbacks are monitored on daily basis. Please do provide feedback as that\'s the only way to improve.