Configuration

Night mode

Square Root

Java Basics Course

Engineers From These Top Companies and Universities Trust EXLskills

1M+ Professionals | 100+ Institutions

This is the EXLskills free and open-source Java Basics Course. It guides learners via explanation, demonstration, and thorough practice, from no more than a basic understanding of Java, to a moderate level of essential coding proficiency.

Is this course FREE?

Yes, this a 100% free course that you can contribute to on GitHub here!

Have more questions?

Math Class

Square Root

One of the more popular Math class functions is the square root function. Like the floor() and ceil() methods, the square root method takes and returns the double datatype. It can be written as follows, Math.sqrt(25), and returns the rounded positive square root. Review the examples below.

This method will return a double number even if the result is a perfect square. The error that will occur if we use a number less than zero is a result of "NaN", which stands for "Not a Number". Therefore, if we were to write Math.sqrt(-4), the return will be "NaN". Imaginary numbers cannot be represented or returned using this method. And lastly, keep in mind that this function will only return one positive square root value.