Make a negative number positive in Java -


I have a Java method in which I add a set of numbers However, I want to say that a negative number is considered positive . Then (1) + (2) + (1) + (- 1) 5 should be equal. I'm sure this is a very easy way to do this - I do not know how !! Any suggestions would be most appreciated.

Just call for example:

  int x = Math .abs (-5);  

will set x to 5 .


Comments