This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Why am i getting NumberFormatException  RSS feed

 
ashwin bhawsar
Ranch Hand
Posts: 62
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
ashwin bhawsar
Ranch Hand
Posts: 62
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ohh, thanks.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!