wood burning stoves*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes NumberFormatException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "NumberFormatException" Watch "NumberFormatException" New topic


Harold Ndou
Ranch Hand

Joined: May 19, 2013
Posts: 34
Hi, can anyone explain to me why Integer.parseInt can throw a NumberFormat Exception from the following code

try { int x = Integer.parseInt("two"); }

I will appriciate your assistance.
Nam Ha Minh
Ranch Hand

Joined: Oct 31, 2011
Posts: 498

Simply "two" is a word, not a number.

PM Me If You Want to get Urgent Help on Java Programming
James X Peterson
Whizlabs Java Support
Ranch Hand

Joined: Feb 26, 2013
Posts: 158
Harold Ndou wrote:

try { int x = Integer.parseInt("two"); }

Integer.parseInt() method will take string as argument but that string need to be numericals not letters. If you pass numericals then it will convert to integer.
Mauro Mazzucco
Ranch Hand

Joined: Apr 26, 2013
Posts: 32

parseInt doesnt know what "two" is, only "2"
Harold Ndou
Ranch Hand

Joined: May 19, 2013
Posts: 34
Thanks so much guys
I agree. Here's the link: http://aspose.com/file-tools
subject: NumberFormatException
Similar Threads
doing a Integer.parseInt within javascript in a JSP
How to convert string to int ?
creating a calculator application - need some math help
urgent please
string to int