Why Math.abs() doesn't work on values that are the MIN_VALUE of the data type?
Absolute value without calling the Math.abs() method?
I think you can probably figure this one out just with a hint.
What happens to negative numbers when they are multiplied by -1?
Note that you can check if numbers are less than zero using if and then do something about less than zero numbers.
If you still get stuck after thinking on that for a few minutes shoot me a pm.
Edit: as long as you don't ask me to just write out all the code for you.
More on reddit.comShould I be using Math.abs?
Problems using Random.nextInt and Math.abs together
Videos
Hello, sorry if this is confusing, but I was going through some programs on Hackerrank, and I tried this snippet for testing to see if the number would fit in the data type
if (Math.abs(num) <= Integer.MAX_VALUE) { // Insert operation here }Maybe I implemented it wrong? But I tried going into the Java docs and found this.
Note that if the argument is equal to the value of Integer.MIN_VALUE, the most negative representable int value, the result is that same value, which is negative.
Is there a reason for this behavior? I'm curious.