Sqrt in Groovy

Find this useful? Support us: Star on GitHub 6
Category: Math | Language: Groovy

In Groovy, you can get the square root of a number using the Math.sqrt() method.

Here's an example of how to get the square root of a number:

`` groovy
def num = 16
def sqrtNum = Math.sqrt(num)
println "Square root of $num is $sqrtNum"


This will output:


Square root of 16 is 4.0

You can also directly get the square root of a number without assigning it to a variable:

groovy
println Math.sqrt(25)

This will output:


5.0
``