codecamp

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 
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定