• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

parseInt() method

 
ronak mehta
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 371
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess white space does not format well as numbers.
 
Muhammad Farooq
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic