Groovy - max()



該方法提供兩個引數的最大值。引數可以是 int、float、long 和 double。

語法

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

引數 − 此方法接受任何基本資料型別作為引數。

返回值 − 此方法返回兩個引數的最大值。

示例

以下是使用此方法的一個示例 −

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

當我們執行以上程式時,將會得到以下結果 −

12.456 
23.12
groovy_numbers.htm
廣告
© . All rights reserved.