Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Konsole {
- // Methode zum einlesen vom Datentyp 'int'
- // Fehlerbehandlung vorhanden
- public static int readInt()
- {
- Scanner scan = new Scanner (System.in);
- int i = 0;
- boolean finish = false;
- while(!finish)
- {
- try
- {
- i = scan.nextInt();
- finish = true;
- }
- catch (Exception e)
- {
- System.out.println("Falsche Eingabe. Bitte ganze Zahl eingeben");
- scan.nextLine();
- }
- }
- return i;
- }
- // Methode zum einlesen vom Datentyp 'double'
- // Fehlerbehandlung vorhanden
- public static double readDouble()
- {
- Scanner scan = new Scanner (System.in);
- double i = 0;
- boolean finish = false;
- while(!finish)
- {
- try
- {
- i = scan.nextDouble();
- finish = true;
- }
- catch (Exception e)
- {
- System.out.println("Falsche Eingabe. Bitte ganze Zahl eingeben");
- scan.nextLine();
- }
- }
- return i;
- }
- // Methode zum einlesen vom Datentyp 'char'
- // Fehlerbehandlung vorhanden
- public static char readChar()
- {
- Scanner scan = new Scanner (System.in);
- char i = '0';
- String k = "aaa";
- boolean finish = false;
- while(k.length() != 1)
- {
- try
- {
- k = scan.nextLine();
- finish = true;
- if(k.length() != 1)
- {
- System.out.println("Falsche Eingabe. Bitte Wiederholen");
- }
- }
- catch (Exception e)
- {
- System.out.println("Falsche Eingabe. Bitte ganze Zahl eingeben");
- scan.nextLine();
- }
- i = k.charAt(0);
- }
- return i;
- }
- // Methode zum einlesen vom Datentyp 'String'
- // Fehlerbehandlung vorhanden
- public static String readString()
- {
- Scanner scan = new Scanner (System.in);
- String i = null;
- boolean finish = false;
- while(!finish)
- {
- try
- {
- i = scan.nextLine();
- finish = true;
- }
- catch (Exception e)
- {
- System.out.println("Falsche Eingabe. Bitte ganze Zahl eingeben");
- scan.nextLine();
- }
- }
- return i;
- }
- }
Add Comment
Please, Sign In to add comment