首页 > 编程知识 正文

java取绝对值函数,java如何使用绝对值

时间:2023-05-05 04:49:15 阅读:183861 作者:1690

** 文章摘要 **

1、绝对值函数,用来获取表达式的绝对值。

2、绝对值函数,实现降序+升序输出。

一、绝对值函数使用说明

绝对值函数是JDK中Math.java中的实现方法,其用来得到表达式的绝对值。

其实现非常简单,源码如下:

/**

* Returns the absolute value of an {@code int} value.

* If the argument is not negative, the argument is returned.

* If the argument is negative, the negation of the argument is returned.

*

*

Note that if the argument is equal to the value of

* {@link Integer#MIN_VALUE}, the most negative representable

* {@code int} value, the result is that same value, which is

* negative.

*

* @param a the argument whose absolute value is to be determined

* @return the absolute value of the argument.

*/

public static int abs(int a) {

return (a < 0) ? -a : a;

}

二、绝对值的特性及其运用。

1、正数的绝对值是其本身。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。