java.lang.StrictMath.abs(long a)方法實例
java.lang.StrictMath.abs(long a) 方法返回一個long值的絕對值。如果該參數不爲負數,則返回該參數。如果參數爲負數,則返回該參數的取反。
聲明
以下是**java.lang.StrictMath.abs()**方法的聲明
public static long abs(long a)
參數
- a -- 這是要來確定其絕對值的參數。
返回值
此方法返回的long值的絕對值。
異常
- NA
例子
下面的例子顯示java.lang.StrictMath.abs()方法的使用。
package com.yiibai; import java.lang.*; public class StrictMathDemo { public static void main(String[] args) { long l1 = 55475693, l2 = -7538911; // returns the absolute value of positive long value long lAbsValue = StrictMath.abs(l1); System.out.println("absolute value of " + l1 + " = " + lAbsValue); // returns the absolute value of negative long value lAbsValue = StrictMath.abs(l2); System.out.println("absolute value of " + l2 + " = " + lAbsValue); } }
讓我們來編譯和運行上面的程序,這將產生以下結果:
absolute value of 55475693 = 55475693 absolute value of -7538911 = 7538911