- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get square root of a number using Math.sqrt in Java
In order to get the square root of a number in Java, we use the java.lang.Math.pow() method. The Math.pow(double a) method accepts one argument of the double data type and returns a value which is the square root of the argument.
Declaration − The java.lang.Math.sqrt() method is declared as follows −
public static double sqrt(double a)
where a is the number whose square root is to be found.
Let us see a program where we find the square root of number using the Math.sqrt() method.
Example
import java.lang.Math; public class Example { public static void main(String[] args) { // declaring and initializing some double values double x = 25; double y = 81; // computing the square roots System.out.println("The square root of "+ x + " is "+ Math.sqrt(x)); System.out.println("The square root of "+ y + " is "+ Math.sqrt(y)); } }
Output
The square root of 25.0 is 5.0 The square root of 81.0 is 9.0
- Related Articles
- Finding square root of a number without using Math.sqrt() in JavaScript
- Finding square root of a non-negative number without using Math.sqrt() JavaScript
- Square root function without using Math.sqrt() in JavaScript
- How to get the square root of a number in JavaScript?
- 8086 program to find the square root of a perfect square root number
- Java program to find the square root of a given number
- Finding square root of a number without using library functions - JavaScript
- PHP – How to get the square root of an arbitrary precision number using bcsqrt() function?
- How to calculate square root of a number in Python?
- 8086 program to find Square Root of a number
- 8085 program to find square root of a number
- Find square root of number upto given precision using binary search in C++
- How to get the square root of 2 in JavaScript?
- What is a number which is a square and square root itself?
- Find the smallest number by which 1458 should be multiplied so as to get a perfect square. Also, find the square root of the square number obtained.

Advertisements