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..!!