If we run the above code by typing a integer value say 3 it produces NumberFormatException in Line 1. Why? When we know that string "3" can be changed into integer value 3 by parseInt() method without any exception.
[ March 26, 2008: Message edited by: gurneeraj singh ]
Thanks Ulf, Acctually I got the answer from your reply, there is whitespace with string str because of the empty char array elements when converted to string str. There are two ways to get rid of this 1) Use str=str.trim(); just above the Line 1 2) Or set the char array size to 1. [ March 26, 2008: Message edited by: gurneeraj singh ]
Hi. Tell you the way to test String value in a program..!! always try to print String value like this System.out.println("["+ str + "]"); so Atmost you know whether string was blank,containing space etc..!!
Dear Ben, I think if we make following changes to code at line a1 & line a2. We are somewhat able to solve the problem of exception at line 1. Please suggest!
SCJP 5.0 93%<br /> <br />SCWCD 5.0 97 %
I will open the floodgates of his own worst nightmare! All in a tiny ad:
Gift giving made easy with the permaculture playing cards