Java Math abs() 方法
示例
返回不同數字的絕對值(正值)
System.out.println(Math.abs(-4.7));
System.out.println(Math.abs(4.7));
System.out.println(Math.abs(3));
定義和用法
abs()
方法返回一個數字的絕對值(正值)。
語法
以下之一
public static double abs(double number)
public static float abs(float number)
public static int abs(int number)
public static long abs(long number)
引數值
引數 | 描述 |
---|---|
數字 | 必需。指定一個數字 |
技術詳情
返回 | 一個表示指定數字絕對值的 double 、float 、int 或 long 值 |
---|
❮ Math 方法