0

I'm unable to catch the InputMismatchException even though I imported java.util.InputMismatchException;

At line 2 :: The import java.util.InputMismatchException cannot be resolvedJava(268435846)
At line 19 :: InputMismatchException cannot be resolved to a typeJava(16777218)

I'm currently using VScode editor

package LabPrograms;
import java.util.InputMismatchException;
import java.util.Scanner;
public class Lab11 {
       public static void main(String args[]){
              Scanner sc = new Scanner(System.in);
              int n,d,res;
              try{
                   System.out.println("Enter two digits: ");
                   n=sc.nextInt();
                   d=sc.nextInt();
                   res=n/d;
                   System.out.println(res);
             }
             catch(ArithmeticException ea)
             {
                   System.out.println("Divide by zero error: "+ea);
             }
             catch(InputMismatchException ei)
             {
                   System.out.println("Invalid input entered: "+ei);
             }
       }
   }
Sanip
  • 1,772
  • 1
  • 14
  • 29
  • The code compiles for me (command line). Try restarting VSCode, or compiling the code from the command line. – Stephen C Dec 25 '21 at 05:31

1 Answers1

1

This code is working fine in NetBeans. Try with some other IDE