![]() |
Why is it throwing "number format exception" ?
Code:
//WAP That convert integer value into binary,octal and hexdecimal.Here is the output ******* 1: Convert number to Binary format ******** ******* 2: Convert number to Octal format ********* ******* 3: Convert number to Hexadecimal format *** Enter Option :1 Enter Number :5643 Binary equivalent of 5643 is 1011000001011 Enter your choice(y/n) :y Here, when i am entering 'y' or value other than 'n' it is throwing exception. ******* 1: Convert number to Binary format ******** ******* 2: Convert number to Octal format ********* ******* 3: Convert number to Hexadecimal format *** Enter Option :Exception in thread "main" java.lang.NumberFormatException: For i nput string: "" at java.lang.NumberFormatException.forInputString(Num berFormatException. java:48) at java.lang.Integer.parseInt(Integer.java:447) at java.lang.Integer.parseInt(Integer.java:476) at numconv.main(numconv.java:24) |
Re: Why is it throwing "number format exception" ?
you type a letter "y", and then you type a line return
read() just reads one character ("y") the line return is still in the stream then when readLine() is called, it reads until it encounters a line return, which is the first character it encounters so it returns an empty line Integer.parseInt() cannot parse an empty string |
Re: Why is it throwing "number format exception" ?
change br.readLine() to br.read();
|
Re: Why is it throwing "number format exception" ?
hi can you please give some explanation for your code i needed some help
|
| All times are GMT +5.5. The time now is 17:50. |