Java Exception Handling (Try-catch)

  • + 0 comments

    sc.nextInt() is used to read integers from the input. However, if the user enters something that is not an integer (e.g., a letter, a decimal number, or a string), sc.nextInt() will throw an InputMismatchException.so that's why we are using inside the try block.