搜索
Java 教程 / Java Math abs() 方法

Java Math abs() 方法

定义和用法abs() 方法返回数字的绝对(正)值。实例返回不同数字的绝对(正)值:System.out.println(Math.abs(-4.7));Syst



定义和用法

abs() 方法返回数字的绝对(正)值。


实例

返回不同数字的绝对(正)值:

System.out.println(Math.abs(-4.7));
System.out.println(Math.abs(4.7));
System.out.println(Math.abs(3)); 

运行实例 »

点击 "运行实例" 按钮查看在线实例


语法

以下之一:

public static double abs(double number)
public static float abs(float number)
public static int abs(int number)
public static long abs(long number)

运行实例 »

点击 "运行实例" 按钮查看在线实例

参数

参数 描述
number 必需。数字。

技术细节

返回: doublefloatintlong 值,表示指定数字的绝对值。