SHARE
TWEET

Untitled

a guest Nov 19th, 2019 99 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2. import java.util.*;
  3.  
  4. public class ExceptionHandling {
  5.     public static void main(String[] args) throws InputMismatchException {
  6.         Scanner input = new Scanner(System.in);
  7.         System.out.print("Enter two integers: ");
  8.    
  9.         try {
  10.             int number1 = input.nextInt();
  11.             int number2 = input.nextInt();
  12.             int result = number1 + number2;
  13.             System.out.println(number1 + " + " + number2 + " = " + result);
  14.         }
  15.         catch (InputMismatchException ex) {
  16.             main();
  17.         }
  18.     }
  19. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top