当前位置:首页 >  站长 >  编程技术 >  正文

Java中绝对值函数使用说明

 2021-01-20 16:47  来源: 网络综合   我来投稿 撤稿纠错

  域名预订/竞价,好“米”不错过

绝对值函数使用说明

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

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 yy@haotui.cn 举报,一经查实,本站将立刻删除。

申请创业报道,分享创业好点子。点击此处,共同探讨创业新机遇!

相关标签
绝对值函数

相关文章

创业项目推荐

热门排行

信息推荐