Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement