• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Maybe a error in Mr Dan's Mock

 
Keen Chen
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Topic -> Lang -> Math
Q 14:
Question 14
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.
g. None of the Above
answer: a c e f
sorry, i don't think F is correct.
say
Math.abs(Interger.MIN_VALUE) == Integer.MIN_VALUE.
 
Keen Chen
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OH
That is the latest version Dec. 4
Thx a lot for Your hard working for us.
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
f is correct. The Java API for Math.abs says:
If the argument is negative, the negation of the argument is returned.
this is exactly what Dan expresses in the option f. If arg is negative, that is, -2 for instance, then -(-2), that is, 2 is returned. Math.abs always returns positive values.
 
Keen Chen
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh?
API say that?
ok, Interger.MIN_VALUE, IS IT NEGATIVE?, yes.
Math.abs(Integer.MIN_VALUE) == Integer.MIN_VALUE.
SO , API HAVE ERROR.
 
Alfred Kemety
Ranch Hand
Posts: 279
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course API is not wrong at this point. The thing is the case you're presenting is very specific and is an exception. This happens because integers in Java are signed, so the MSB is for the sign of the number.
Integer.MIN_VALUE = 0x8FFFFFFF
 
Keen Chen
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,Alfred, yes, i konw
and i know why abs(Integer.MIN_VALUE) still equals itself. ,it's a exception.
but, that's not question.
the question which we are talk about is :
is that expression RIGHT?
because the EXCEPTION, reduction to absurdity , the expression is error.
at least, it's not accurate .
That's all
 
Alfred Kemety
Ranch Hand
Posts: 279
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The sentence stated in option F is true

pritns true
 
Dan Chisholm
Ranch Hand
Posts: 1865
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Alfred.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic