设为首页 - 加入收藏 PHP编程网 - PHP站长网 (http://www.52php.cn)- 电商,百科,编程,业界,移动互联,5G,云计算,站长网!
热搜: 娱乐 服务 站长之家 百度
当前位置: 首页 > 编程 > 正文

Java中绝对值函数使用说明

发布时间:2021-01-21 11:11 所属栏目:[编程] 来源:网络综合
导读:绝对值函数使用说明 绝对值函数是JDK中Math.java中的实现方法,其用来得到表达式的绝对值。 其实现非常简单,源码如下: /** * Returns the absolute value of an {@code int} value. * If the argument is not negative, the argument is returned. * If

绝对值函数使用说明

绝对值函数是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.
 *
 * <p>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;
 }

【免责声明】本站内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。

推荐文章
热点阅读