aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Maybe a error in Mr Dan's Mock Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Maybe a error in Mr Dan Watch "Maybe a error in Mr Dan New topic
Author

Maybe a error in Mr Dan's Mock

Keen Chen
Ranch Hand

Joined: Nov 12, 2002
Posts: 47
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.


SCJP 1.4 100% @ Peking, China <br />~~~~~~~~~~~~~~~~~~~~~<br />但使龙城飞将在, 不教胡马度阴山!
Keen Chen
Ranch Hand

Joined: Nov 12, 2002
Posts: 47
OH
That is the latest version Dec. 4
Thx a lot for Your hard working for us.
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
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.


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Keen Chen
Ranch Hand

Joined: Nov 12, 2002
Posts: 47
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

Joined: Aug 14, 2002
Posts: 279
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


Alfred Raouf - Egypt - SCJP 1.4<br />Kemety.equals(Egyptian) // returns true
Keen Chen
Ranch Hand

Joined: Nov 12, 2002
Posts: 47
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

Joined: Aug 14, 2002
Posts: 279
The sentence stated in option F is true

pritns true
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
Thank you Alfred.


Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Maybe a error in Mr Dan's Mock