Java abs() 方法

Java 教程 · 2019-02-08 11:29:52

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

点击查看所有 Java 教程 文章: https://www.codercto.com/courses/l/12.html

查看所有标签

Spark

Spark

Bill Chambers、Matei Zaharia / O′Reilly / 2017-10-31 / GBP 39.99

Learn how to use, deploy, and maintain Apache Spark with this comprehensive guide, written by the creators of the open-source cluster-computing framework. With an emphasis on improvements and new feat......一起来看看 《Spark》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器