Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.*;
- public class ExceptionHandling {
- public static void main(String[] args) throws InputMismatchException {
- Scanner input = new Scanner(System.in);
- System.out.print("Enter two integers: ");
- try {
- int number1 = input.nextInt();
- int number2 = input.nextInt();
- int result = number1 + number2;
- System.out.println(number1 + " + " + number2 + " = " + result);
- }
- catch (InputMismatchException ex) {
- main();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement