Saturday, 12 April 2014

NumberformatExceptionDemo

class NumberformatExceptionDemo
{

public static void main(String args[])
  {
    String str1= "10";
    int x = Integer.parseInt(str1);
    System.out.println(x*x);    // prints 100

    try
    {
      String str2= "ten";
      int y = Integer.parseInt(str2);
    }
    catch(NumberFormatException e)
    {
      System.err.println("Unable to format. " + e);
    }

}
}

No comments:

Post a Comment