Number Format Exception

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

 

We have 1000s of tutorials on our website. Search Tutorials tutorials on our website.

Share on Google+Share on Google+

Number Format Exception

Posted on: June 8, 2013 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: Number Format Exception  

Post your Comment


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

Ads

 

Ads