Groovy - max() method
The method max() method gives the larger of the two arguments. The argument can be int, float, long, double.
Syntax
double max(double arg1, double arg2) float max(float arg1, float arg2) int max(int arg1, int arg2) long max(long arg1, long arg2)
Parameters
arg1 − A primitive data type.
arg2 − Corresponding primitive data type.
Return Value
This method returns the larger of the two arguments.
Example - Usage of max() method for double values
Following is an example of the usage of this method −
Example.groovy
class Example {
static void main(String[] args){
double d = 12.123;
double e = 12.456;
println(Math.max(d, e));
}
}
Output
When we run the above program, we will get the following result −
12.456
Example - Usage of max() method for int values
Following is an example of the usage of this method −
Example.groovy
class Example {
static void main(String[] args){
int d = 12;
int e = 13;
println(Math.max(d, e));
}
}
Output
When we run the above program, we will get the following result −
13
Example - Usage of max() method for float values
Following is an example of the usage of this method −
Example.groovy
class Example {
static void main(String[] args){
float d = 12.123f;
float e = 12.456f;
println(Math.max(d, e));
}
}
Output
When we run the above program, we will get the following result −
12.456
groovy_numbers.htm
Advertisements