answers given were bcefh... i heard that NAN comes only when u try to take the sqareroot of negative number and why not short min value when there is int minvalue ..and i heard that there is no -0.0 only 0.0 so how come h...
The purpose of these type of mock examination questions is to make you read the API for the Math.abs method(s). I wrote the methods' signatures and return parameters on postcards and carried them around reading them on the bus, tram, train, everywhere and everytime I had a few minutes to spare. I've forgotten them now, but I certainly know where to find the answers. So look up every option in the Java API documentation.
NAN comes only when u try to take the sqareroot of negative number
Can also get NaN with 0.0/0.0 In writing code to test NaN I've found that an expression in which any part results in an NaN will resolve to NaN.
why not short min value when there is int minvalue...
The Short.MIN_VALUE will be implicitly cast to an int in the abs() call which results in return of positive 32768. Thus cannot be a return value of abs(). Key to this part is knowing the abs() signatures. K&B book stressed knowing them for the 1.4 test.
For floating point numbers, there is a difference between -0.0 and 0.0. For integer types, there is only 0.
As noted above, this question wants you to understand how to look things up in the API. The answers are all right there. For one thing, there is no version of abs() that returns a short, so it cannot return Short.MIN_VALUE.
The docs also explain all about the other answers as well.
thanks all of u .... i knew it about the return types of abs..but looking at NaN got confused.. thanks .. int abs(int abs) float abs(float abs) long abs(long abs) double abs(double abs)
so with this there cant be any short or byte or char....right .. System.out.println(Math.abs(-5/0.0));returns me only positive infinity .. so there cant be negative infinity ... System.out.println(Math.abs(-0.0/0.0)); returns me NaN..and there is no as such negative value for it... System.out.println(Math.abs(-0.0)); returns positive .. Integer.MIN_VALUE Long.MIN_VALUE these must be negative right then how can abs return me negative??