Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Java Parse int Exception 
 

Static method in parseInt is derived from package java.lang.integer.public static method int parseInt(String s) gives you NumberFormatException. This parses the argument that passed as String into decimal integer.

 

Java Parse int Exception

                         

Static method in parseInt is derived from package java.lang.integer.public static method int parseInt(String s) gives you NumberFormatException. This parses the argument that passed as String into decimal integer. Even the character present in the string should be decimal one, exclude the first character, that may be ASCII subtract sign '-' ('c9808') to indicate a negative number. In return you get a integer value, if the argument and the radix is 10  given to the argument parseInt(String s,int )method.

Understand with Example

We declare a Public class name' inputtest'.Inside the main static method parseInt( ) method is used to convert a string format into a numeric integer. The Parameter Used in parseInt(java lang.String,int )method are 

1) s- Stand for string passed as an argument in parseInt Method and string contain the integer.

2) radix-Return the integer present in argument in decimal.

 throws you Number Format Exception, if the string does not contain parsable integer.

   
     import java.io.*;

    public class mytest
{
    public static void main(String[] args) throws IOException
  
{
     String s;
     int i;
     System.out.print("Enter a integer : ");
     s = readString();
     i = Integer.parseInt(s);

}

    public static String readString() throws IOException
{
    String Line = "";
    int c;
    while (true)
{
     c = System.in.read();
     if(c ==20)
     break;
     Line += (char) c;
}
    return Line;
  
}

 

 

Output on Command Prompt


C:\Documents and Settings\Administrator>cd\

C:\>cd saurabh\

C:\saurabh>javac mytest.java

C:\saurabh>java mytest
Enter a integer: 7
"xception in thread "main" java.lang.NumberFormatException: For input string: "7
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at inputtest.main(inputtest.java:12)

                         

» View all related tutorials
Related Tags: c exception io stack type exec uri lock this block exe row handle program to execution ram each pos ast

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.