public class FindC extends MiniJava {
    public static int[] readArray(int number) {
        // number = Anzahl zu lesender Elemente
        int[] result = new int[number]; // Feld anlegen
        for (int i = 0; i < number; ++i) {
            result[i] = read();
        }
        return result;
    }

    public static int find(int[] a, int x) {
        int n1 = 0;
        int n2 = a.length-1;
        while (true) {
            int t = (n2 + n1) / 2;
            if (x == a[t]) return t;
            else if (n1 == n2) return -1;
            else if (x > a[t]) n1 = t+1;
            else if (n1 < t) n2 = t-1;
            else return -1;
        } // end of while
    } // end of find    

    // Jetzt kommt das Hauptprogramm
    public static void main(String[] args) {
        int n = read("Länge des Arrays");
        int[] arr = readArray(n);

        int x = read("Zu suchende Zahl");

        int res = find(arr,x);
        if (res == -1)
            write("Zahl nicht gefunden!");
        else
            write("Zahl an Position "+res+" gefunden");
    } // end of main()    
}


