/** * @author monika heiner * @version 1.01 * @date 14.05.2012 * @class ExceptionDemo1 */ // keinerlei exception handling // standard runtime exceptions fuehren zum Programmabbruch import java.util.Scanner; public class ProgramErrorsDemo { public static void main(String[] argv) { int a, op; double x; int[]array = new int[1]; System.out.println("Willkommen zur Demonstration beliebter Programmierfehler"); op = getInt( "Operationsauswahl: \n" + " 0 -->> exit\n" + " 1 -->> ueberschreiten des int-Wertebereichs\n" + " 2 -->> unterschreiten des int-Wertebereichs\n" + " 3 -->> ueberschreiten des double-Wertebereichs\n" + " 4 -->> unterschreiten des positiven double-Wertebereichs\n" + " 5 -->> exception - array index out of bound\n" + " 6 -->> exception - null pointer\n" + "Operation: "); while ((op > 0) && (op <= 6)) { switch (op) { case 1 :a = java.lang.Integer.MAX_VALUE; System.out.println(" max: "+ a + "\n max+1: " + (a+1)); break; case 2 :a = java.lang.Integer.MIN_VALUE; System.out.println(" min: "+ a + "\n min-1: " + (a-1)); break; case 3 :x = java.lang.Double.MAX_VALUE; System.out.println(" max: "+ x + "\n max+1 " + (x+1)); break; case 4 :x = java.lang.Double.MIN_VALUE; System.out.println(" min: "+ x + "\n min-1: " + (x-1)); break; case 5 :a = array[1]; System.out.println("komme ich bis hier?"); break; case 6 :array = null; a = array[1]; System.out.println("komme ich bis hier?"); break; } // switch op = getInt("next Operation: "); } // while System.out.println("auf wiedersehen!"); } // main // Vereinfachung der Eingabe static int getInt(String message) { Scanner in = new Scanner(System.in); System.out.print(message); return in.nextInt(); } // getInt } // ProgramErrorsDemo