Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Exceptions Number Format Exception

 
 

Share on Google+Share on Google+

Number Format Exception

Advertisement
NumberFormatException is a type of RuntimeException which is generated when a programmer try to convert String into integer.

Number Format Exception

In this section you will learn about Number Format Exception in java. NumberFormatException is derived from RuntimeException class, generally when a programmer tries to attempt to convert a string into integer which is not appropriate. A NumberFormatException in java occur when trying to convert a string into a number.

public class NumberFormarException {

public static void main(String args[])
{
	 
	 int in=Integer.parseInt("10");
	 System.out.println("Example = " +in );
}
}

In the above code we are trying to convert a string value 10 to int . but when we are trying to pass a value  "Rose India " to integer.parseInt() method it will raise a compile time error. Because a "Rose India" is not a legal string representation of  an int value.

public class NumberFormarException {

public static void main(String args[])
{
	
	 int in=Integer.parseInt("Rose India");
	 System.out.println("Example = " +in );
    }
  }

After compiling this above code the compile time error is like as follows:

 

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 8, 2013

Related Tutorials

Discuss: Number Format Exception  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com