Skip to main content

L10

ExceptionsLab.java

import java.util.Scanner;

public class ExceptionLab {
    public  static void main(String[] args) {
        int[] myInts = new int[4];
        Scanner scan = new Scanner(System.in);

        try {
            for (int i = 0; i != 4; i++) {
                System.out.println("Enter a integer: ");
                int num = Integer.parseInt(scan.nextLine());
                myInts[i] = num;
            }

            System.out.println("Your Numbers");

            for (int i = 0; i != 4; i++) {
                System.out.print(myInts[i] + " ");
            }
        }
        catch (NumberFormatException myEx){
            System.out.println("You should have entered a Integer you TWAT!");
        }
    }
}