首页 > 编程知识 正文

java怎么取绝对值,java构造方法

时间:2023-05-03 14:40:23 阅读:24558 作者:3071

绝对值在java中有时非常有用,合伙人们知道应该怎么写绝对值吗? 有什么特性? 一起看看吧。

一、绝对值函数

在Java中,可以使用math.ABS (例如Math.abs(1.3-5.6 ) )方法轻松地进行绝对值计算。

自己写也很简单的publicintegerabs(integera ) )。

returna0? a:-a;

}

绝对值源代码:/**

* returnstheabsolutevalueofan { @ codeint } value。

*Iftheargumentisnotnegative,theargumentisreturned。

*Iftheargumentisnegative,thenegationoftheargumentisreturned。

*

*

otethatiftheargumentisequaltothevalueof

*{@linkInteger#MIN_VALUE},themostnegativerepresentable

*{@codeint}value,theresultisthatsamevalue,whichis

*否定。

*

* @ paramatheargumentwhoseabsolutevalueistobedetermined

* @ returntheabsolutevalueoftheargument。

*/

公共统计数据中心(inta )。

{

ret

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