king0207

Math.abs() 返回参数的绝对值。参数可以是 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 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-11-27
  • 2022-12-23
  • 2021-11-27
  • 2021-11-12
  • 2022-02-17
  • 2021-10-19
猜你喜欢
  • 2021-07-16
  • 2021-06-03
  • 2022-12-23
  • 2021-11-27
  • 2021-11-27
  • 2021-07-06
  • 2021-12-07
相关资源
相似解决方案