A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Elasticsearch in Action
this week in the
Programmer Certification (SCJP/OCPJP)
Joined: Nov 07, 2003
May 22, 2004 09:54:00
The double data type can accept an int rite?
Why the following gives a run time exception?Can anybody pl explain?Thanks.
Double d1 = new Double("0x10");
[ May 22, 2004: Message edited by: Barry Gaunt ]
Joined: Jul 21, 2003
May 22, 2004 11:17:00
The constructor that accepts
for wrapper classes is more restrictive from the one that accepts primitives. That is why you can't pass a hex string value.
Take this for an example:
Double d1 = new Double("010");
d1.doubleValue(); // print the result
is treated as an integer number of base 10, the leading zero (which represents that the number is octal) is simply ignored. So the value stored in 'd1' is 10, and not 12 as you might expect.
- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. - What truth? - That there is no spoon!!!
Joined: Aug 03, 2002
May 22, 2004 11:37:00
For this kind of question it's a good idea to look at the
1.4.2 API. It's a much better source of information than one's own intuition.
Ask a Meaningful Question
Getting someone to think and try something out is much more useful than just telling them the answer.
I agree. Here's the link:
short to bit ?
Wrapper class question from Danchisolm
Explanation needed for this program
How to pass a long in ...Long ll = Long.valueOf(3L);//gives
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015