This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi Dan, For the below program why 'f' is also included in the answer. Which of the following statements are true in terms of the java.lang.Math.abs method? a. Four overloaded versions of abs exist. b. An ArithmeticException is declared in the throws clause. c. The type of the return value depends on the type of the argument. d. The returned value is always of a floating-point primitive type. e. If the argument is greater than or equal to zero then the returned value is equal to the argument. f. If the argument, arg, is less than zero then the returned value is -arg. Thx
public static int abs(int a)Returns the absolute value of an int value. If the argument is not negative, the argument is returned. If the argument is negative, the negation of the argument is returned. 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.
As you can see here for negative values, their negation will be returned. And specially for Integer.MIN_VALUE, its negation is just the same as itself and so is Long.MIN_VALUE. It could be wrong also if the statement is changed to: