Java中绝对值函数使用说明
绝对值函数使用说明
绝对值函数是JDK中Math.java中的实现方法,其用来得到表达式的绝对值。
其实现非常简单,源码如下:
/**
* Returns the absolute value of an int} value.
* If the argument is not negative, the argument is returned.
* If the argument is negative, the negation of the argument is returned.
*
* <p>Note that if the argument is equal to the value of
* Integer#MIN_VALUE}, the most negative representable
* 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;
}
版权申明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
蓝大富博客 » Java中绝对值函数使用说明
蓝大富博客 » Java中绝对值函数使用说明