Number Format exception using try-catch block in java.

Write a program to handle the Number Format exception using try-catch block in java.

package Exception_demo;

import java.util.*;
public class numberformat_soln 
{
    public static void main(String args[])
    {
        Scanner s=new Scanner(System.in);
        String s1;
        System.out.println("enter string");
        s1=s.next();
        try
        {
            int i=Integer.parseInt(s1);
        }
        catch(Exception e)
        {
            System.out.println(e);
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *