Hi, I've hit a question that is on two mocks: On Jxam: System.out.println(Integer.parseInt(null)); answer = 0 On another mock (forgot name): System.out.println(Integer.parseInt(null)); answer = error
Now I initially thought it was 0, but I took the second one first and got error, so I remembered this, and then on Jxam I get it wrong again. Can someone please clarify this please? All help appreciated, Travis B.
Travis, this is what happens when I tried to run it: Exception in thread "main" java.lang.NumberFormatException: null at java.lang.Integer.parseInt(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at Parser.main(Parser.java:5) so, I guess the answer is error!?
The early bird may get the worm, but the second mouse gets the cheese.........<br /> <br />Sun Certified Programmer for Java 2 Platform<br />Sun Certified Web-Component Developer for J2EE Platform
Joined: Jan 24, 2002
Hi Thanks Rowan. and a big DUH!! for me. lol After all my studying overnight and everything.... the simplest thing would have been to test it myself, but I missed it. lol. This must mean I need sleep. Thanks for your help Rowan. Travis B.
Travis here is one way to think about it (in java). A null is an undefined value, while zero in a defined value. So trying to display an 'null' value could have one of two results: a) it outputs the literal 'null' b) it results in an runtime error there is no easy way to guess if the correct answer is a) or b) without actually trying it out with java and seeing how the creators of the language wanted it to (mis)behave [ March 06, 2002: Message edited by: Rajinder Yadav ]
<a href="http://www.rajindery.com" target="_blank" rel="nofollow">Rajinder Yadav</a><p>Each problem that I solved became a rule which served afterwards to solve other problems. --Rene Descartes