Reputation: 15069
I forgot the function in Java to calculate the magnitude of an integer. help please..
|5| = +5 = 5
|-5| = +5 = 5
so if a - b is - x
mag (a - b) is x a posstive number..
Upvotes: 9
Views: 15931
Reputation: 5782
I believe you are looking for Math.abs(). Using this function:
5 = Math.abs(5) = Math.abs(-5)
Upvotes: 17
Reputation: 2493
The function's in the Math library and is called abs()
(short for "absolute value").
Upvotes: 2