该方法给出参数的绝对值。参数可以是int,float,long,double,short,byte。
以下是此方法的所有变体-
double abs(double d) float abs(float f) int abs(int i) long abs(long lng)
public class Test { public static void main(String args[]) { Integer a=-8; double d=-100; float f=-90; System.out.println(Math.abs(a)); System.out.println(Math.abs(d)); System.out.println(Math.abs(f)); } }
这将产生以下输出-
8 100.0 90.0
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)
HarmonyOS快速入门与实战 -〔QCon+案例研习社〕