Groovy - min()



该方法提供两个参数中较小的一个。参数可以是 int、float、long、double。

语法

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

参数 − 该方法接受任何基本数据类型作为参数。

返回值 − 该方法返回两个参数中较小的一个。

示例

以下是使用该方法的一个示例 −

class Example { 
   static void main(String[] args) { 
      System.out.println(Math.min(12.123, 12.456)); 
      System.out.println(Math.min(23.12, 23.0)); 
   } 
}

当我们运行上述程序时,将获得以下结果 −

12.123 
23.0 
groovy_numbers.htm
广告
© . All rights reserved.