在java中计算数字的大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9706869/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
calculating magnitude of a number in java
提问by Ahmed
I forgot the function in Java to calculate the magnitude of an integer. help please..
我忘记了 Java 中计算整数大小的函数。请帮忙..
|5| = +5 = 5
|5| = +5 = 5
|-5| = +5 = 5
|-5| = +5 = 5
so if a - b is - x
所以如果 a - b 是 - x
mag (a - b) is x a posstive number..
mag (a - b) 是 xa 正数..
采纳答案by Dan W
I believe you are looking for Math.abs(). Using this function:
我相信您正在寻找Math.abs()。使用此功能:
5 = Math.abs(5) = Math.abs(-5)
回答by bouteillebleu
The function's in the Math libraryand is called abs()
(short for "absolute value").
该函数位于 Math 库中并被调用abs()
(“绝对值”的缩写)。
回答by Lajos Arpad
Math.abs() is the function you are looking for.
Math.abs() 是您正在寻找的函数。