Write a program to handled the InputMismatch Exception

Write a program to handled the InputMismatch Exception

Program
import java.util.*;
class Main
{
    public static void main(String args[])
    {
        int x,y,z;
        System.out.println("Enter x,y values :");
        Scanner s=new Scanner (System.in);
        try
        {
            x=s.nextInt();
            y=s.nextInt();
            z=x/y;
            System.out.println("Division of two number is : "+z);
        }
        catch(InputMismatchException e)
        {
            System.out.println("Please Enter Numbers Only");
        }
    }
}

Output:

Enter x,y values : 10 2
Division of two number is : 5

Enter x,y values : 10 #
Please Enter Numbers Only


Exception Handling In Java



More Questions


161 . Write a program to handled the Arithmetic Exception
162 . Write a program to handled the InputMismatch Exception
163 . Write a program to handled the ArrayIndexOutOfBoundsException
164 . Write a program to handled the StringIndexOutOfBoundsException
165 . Write a java program to know exception details using Exception class
166 . Write a java program to know above exception details using printStackTrace() Method
167 . Write a java program to know above exception details using getMessage Method
168 . Write a Throws Keyword Program
169 . Write a Finally block Program
170 . Write a program to handle negative age exception
171 . Write a program to handle negative salary exception