java.lang.StrictMath.min(float a, float b)方法實例
java.lang.StrictMath.min(float a, float b) 方法返回兩個浮點的最小值。
如果該參數具有相同的值,其結果爲參數相同的值。如果任一值爲NaN,那麼結果爲NaN。
這種方法認爲負零嚴格小於正零。如果一個參數是正零,而另一個是負零,則結果爲負零。
聲明
以下是**java.lang.StrictMath.min()**方法的聲明
public static float min(float a, float b)
參數
a -- 這是一個float值。
b -- 這是另一個float值。
返回值
這個方法返回a和b之間的最小值。
異常
- NA
例子
下面的例子顯示java.lang.StrictMath.min()方法的使用。
package com.yiibai; import java.lang.*; public class StrictMathDemo { public static void main(String[] args) { float f1 = 50 , f2 = 100, f3 = -25; // both positive values double minValue = StrictMath.min(f1, f2); System.out.println("StrictMath.min(50, 100) : " + minValue); // one positive and one negative value minValue = StrictMath.min(f1, f3); System.out.println("StrictMath.min(50, -25) : " + minValue); } }
讓我們來編譯和運行上面的程序,這將產生以下結果:
StrictMath.min(50, 100) : 50.0 StrictMath.min(50, -25) : -25.0