SHARE
TWEET

Untitled

a guest Nov 19th, 2019 93 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.  
  7.         System.out.println("Enter two real numbers to add together.");
  8.         Scanner input = new Scanner(System.in);
  9.         boolean continueInput = true;
  10.    
  11.         try {
  12.             System.out.print("Enter two integers: ");
  13.             int number1 = input.nextInt();
  14.             int number2 = input.nextInt();
  15.             int result = number1 + number2;
  16.             System.out.println(number1 + " + " + number2 + " = " + result);
  17.            
  18.             continueInput = false;
  19.         }
  20.         catch (InputMismatchException ex) {
  21.             main();
  22.         }
  23.     }
  24. }
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