import java.util.InputMismatchException;
import java.util.Scanner;

public class Exceptions {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        while(true) {
            try {
                System.out.print("Bitte gebe eine Zahl zwischen 1 und 6 ein: ");

                // sc.close();
                int zahl = sc.nextInt();

                System.out.println("Die eingegebene Zahl lautet: " + zahl);

                break;
            } catch (InputMismatchException ex) {
                System.out.println("Du hast keine Zahl eingegeben!");
            } catch (IllegalStateException ex) {
                System.out.println("Der Scanner ist geschlossen!");
            }
            sc.nextLine();
        }


        int[] zahlen = new int[4];
        try {
            zahlen[0] = 2;
            zahlen[1] = 4;
            zahlen[2] = 1;
            zahlen[3] = 9;
            zahlen[4] = 3;

            System.out.println("Hallo");
        } catch(ArrayIndexOutOfBoundsException ex) {
            System.out.println("Wir haben auf einen nicht verfügbaren Index zugegriffen.");

            System.out.println("Array-Inhalt:");
            for (int i = 0; i < zahlen.length; i++) {
                System.out.println("\tIndex " + i + ": " + zahlen[i]);
            }
        }
    }

}
