java使用abs函数_Java Math abs()用法及代码示例
java.lang.Math.abs()返回給定參數的絕對值。
如果參數不為負,則返回參數。
如果參數為負,則返回參數的取反。
用法:
public static DataType abs(DataType a)
a:the argument whose absolute value is to be determined
返回: This method returns the absolute value of the argument.
如果參數為double或float類型:
如果參數為正零或負零,則結果為正零。
如果參數為無窮大,則結果為正無窮大。
如果參數為NaN,則結果為NaN。
如果參數為int或long類型:
如果參數等于Integer.MIN_VALUE或Long.MIN_VALUE的值,則最負
可表示的int或long值,結果是相同的值,為負。
// Java program to demonstrate working
// of java.lang.Math.abs() method
import java.lang.Math;
class Gfg {
// driver code
public static void main(String args[])
{
float a = 123.0f;
float b = -34.2323f;
double c = -0.0;
double d = -999.3456;
i
總結
以上是生活随笔為你收集整理的java使用abs函数_Java Math abs()用法及代码示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 选择降薪45%,从互联网到国企
- 下一篇: java美元兑换,(Java实现) 美元