Max Min in Groovy

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

In Groovy, you can get the maximum or minimum of two numbers by using the Math.max or Math.min functions respectively. Here are examples:

def a = 5
def b = 10

// get the maximum of a and b
def maxNumber = Math.max(a, b)
println("The maximum of $a and $b is $maxNumber")

// get the minimum of a and b
def minNumber = Math.min(a, b)
println("The minimum of $a and $b is $minNumber")

Output:

The maximum of 5 and 10 is 10
The minimum of 5 and 10 is 5