class MyRandom{ int max; java.util.Random random = new java.util.Random(); MyRandom(int m){max = m;} int rand (){ int r = random.nextInt(); if (r < 0) r = -r; return r % max; } } class NichtGefunden extends Exception{ public NichtGefunden(){super();} } class ArraySuche{ int[] a; ArraySuche(int n){ a = new int[n]; for (int i=0; i < n; i++) a[i]=(int) (42*Math.random()); } int suche(int was)throws NichtGefunden{ int n= a.length; for (int i = 0; i < n; i++) if (a[i] == was) return i; throw new NichtGefunden(); } int spezialSuche()throws NichtGefunden{ return suche(41); } } class Except { public static void main(String args[]) { ArraySuche arr = new ArraySuche(99); for (int i = 0; i < 45; i++){ try { arr.suche(i); System.out.println(i + " gefunden!"); } catch(NichtGefunden e){ System.out.println(i + " wurde nicht gefunden!"); } } } }