1 // Einstieg.java
2
3 import java.util.Scanner;
4
5 /** 6 * Einstieg ist ein kleines Java-Programm. 7 * Es verwendet die Klassen Scanner und System aus der Java-Bibliothek. 8 * @author H.Drachenfels 9 * @version 27.4.2015 Version mit statischem Initialisierungsblock 10 */
11 public final class Einstieg {
12 private Einstieg() { }
13
14 static {
15 try {
16 System.out.print("Einstieg.class wird geladen ");
17
18 for (int i = 0; i < 10; ++i) {
19 System.out.print('.');
20 System.out.flush();
21 Thread.sleep(1000);
22 }
23
24 System.out.println();
25 } catch (InterruptedException x) {
26 System.out.println(" Abbruch!");
27 System.exit(1);
28 }
29 }
30
31 private static final Scanner EINGABE = new Scanner(System.in);
32
33 /** 34 * main ist der Startpunkt des Programms. 35 * main verwendet die Methoden print und printf zum ausgeben von Text 36 * sowie die Methoden next und nextInt zum einlesen von Text 37 * und einer ganzen Zahl. 38 * @param args wird nicht verwendet 39 */
40 public static void main(String[] args) {
41 System.out.print("Vorname: ");
42 String vorname = EINGABE.next();
43
44 System.out.print("Anzahl bisher geschriebener Java-Programme: ");
45 int anzahl = EINGABE.nextInt();
46
47 System.out.printf("%ss %d. Java-Programm funktioniert!%n",
48 vorname, anzahl + 1);
49 }
50 }
51