Groovy Operators

Control Statements

Groovy File Handling

Groovy Error & Exceptions

Groovy Multithreading

Groovy Synchronization

Groovy - min() method



The method min() method gives the smaller of the two arguments. The argument can be int, float, long, double.

Syntax

double min(double arg1, double arg2) 
float min(float arg1, float arg2) 
int min(int arg1, int arg2) 
long min(long arg1, long arg2)

Parameters

  • arg1 − A primitive data type.

  • arg2 − Corresponding primitive data type.

Return Value

This method returns the smaller of the two arguments.

Example - Usage of min() 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.min(d, e)); 
   } 
}

Output

When we run the above program, we will get the following result −

12.123

Example - Usage of min() 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.min(d, e)); 
   } 
}

Output

When we run the above program, we will get the following result −

12

Example - Usage of min() 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.min(d, e)); 
   } 
}

Output

When we run the above program, we will get the following result −

12.123
groovy_numbers.htm
Advertisements