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://codercto.com/courses/l/12.html

查看所有标签

Two Scoops of Django

Two Scoops of Django

Daniel Greenfeld、Audrey M. Roy / CreateSpace Independent Publishing Platform / 2013-4-16 / USD 29.95

Two Scoops of Django: Best Practices For Django 1.5 is chock-full of material that will help you with your Django projects. We'll introduce you to various tips, tricks, patterns, code snippets, and......一起来看看 《Two Scoops of Django》 这本书的介绍吧!

URL 编码/解码
URL 编码/解码

URL 编码/解码

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具