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