绝对值在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