wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Why am i getting NumberFormatException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why am i getting NumberFormatException" Watch "Why am i getting NumberFormatException" New topic
Author

Why am i getting NumberFormatException

ashwin bhawsar
Ranch Hand

Joined: Mar 16, 2011
Posts: 62

I tried out the following :

int a=Integer.parseInt("11",2);
System.out.print(a); // output 3

int b=Integer.parseInt("015",8);
System.out.print(b);// output 13

int c=Integer.parseInt("0xf", 16); // NumberFormatException


I did not get why i am getting the exception.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

From the documentation:
Parses the string argument as a signed integer in the radix specified by the second argument. The characters in the string must all be digits of the specified radix (as determined by whether Character.digit(char, int) returns a nonnegative value), except that the first character may be an ASCII minus sign '-' ('\u002D') to indicate a negative value.


So you want


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
ashwin bhawsar
Ranch Hand

Joined: Mar 16, 2011
Posts: 62

Ohh, thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why am i getting NumberFormatException
 
Similar Threads
how to achieve this ?
Conversion of Object to int
Multi Dimensional Array
String of numerics
wrong output