import java.io.IOException; class Element{ int inhalt; Element(int i){ inhalt = i;} } class MyRandom{ static private int max = 52; static private java.util.Random RGen = new java.util.Random(); static void setMax( int m){ max = m;} static Element zufall(){ int i = Math.abs(RGen.nextInt()); return new Element(i % max); } } class ArraySuche { final int anzahl = 42; Element[] cont = new Element[anzahl]; ArraySuche(){ for (int i=0; i < cont.length; i++) cont[i] = MyRandom.zufall(); } boolean P(Element e){return e.inhalt == 42;} Element linSuche(){ return linSuche(cont);} Element linSuche(Element[] a){ for ( Element e : a) if (P(e)) return e; return null; } } public class LinSuche2 { public static void main(String args[]) { System.out.println("Lineare Suche 2"); System.out.println(""); ArraySuche L = new ArraySuche(); Element e = L.linSuche(); if (e != null) System.out.println("Gefunden !"); else System.out.println("Nicht gefunden !"); } }