设为首页 - 加入收藏 ASP站长网(Aspzz.Cn)- 科技、建站、经验、云计算、5G、大数据,站长网!
热搜: 数据 创业者 手机
当前位置: 首页 > 综合聚焦 > 编程要点 > 正文

Java中绝对值函数使用说明

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

绝对值函数使用说明

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

(编辑:ASP站长网)

    网友评论
    推荐文章
      热点阅读