aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes parseInt() method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "parseInt() method" Watch "parseInt() method" New topic
Author

parseInt() method

ronak mehta
Greenhorn

Joined: Aug 14, 2001
Posts: 23
if
int i=0;
char c='a';
then
is it possible
i=Integer.parseInt(""+(int)c);
is i get integer value if yes then how? parseInt give integer value which is conveted in Integer object here am i right?
Desai Sandeep
Ranch Hand

Joined: Apr 02, 2001
Posts: 1157
Ronak,
Why donot you try these codes in your machine?It will help you to get used to these things.
Try this...

And also this...

And explain any errors you get, if any!
Answer the following:

  1. When does Integer.parseInt(String) throw an Exception?
  2. What Exception does it throw?

  3. Hope this helps,
    Sandeep
    SCJP2, OCSD(Oracle JDeveloper), OCED(Oracle Internet Platform)
    [This message has been edited by Desai Sandeep (edited August 30, 2001).]
Cameron Park
Ranch Hand

Joined: Apr 06, 2001
Posts: 371
I guess white space does not format well as numbers.
Muhammad Farooq
Ranch Hand

Joined: May 08, 2001
Posts: 356
The method parseInt(Strings s) of the Integer class takes a String argument and adding " " with int(c) makes it a String that can be accepted as String and it throws NumberFormatException - if the string does not contain a parsable integer.
HTH
--Farooq

Muhammad Farooq<br />Sun Certified Programmer for Java 2 Platform<br />Oracle8i Certified Professional Database Administrator
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: parseInt() method