JustPaste
HomeCategoriesAboutDonateContactTerms of UsePrivacy Policy
JustPaste

Free online notepad — write and share instantly

Navigate

  • Home
  • Timeline
  • Categories

Info

  • About
  • Donate
  • Contact

Legal

  • Terms of Use
  • Privacy Policy

© 2026 JustPaste.app. All rights reserved.

Made with ♥ by JustPaste

hi | JustPaste.app
3 months ago0 views
👨‍💻Programming

hi

public class Suchen
{
    // Deklaration der globalen Variablen
    private int[] feld= new int [1000]; 
    int[] feld2 ={92, 240, 280, 362, 364, 370, 443, 657, 677, 753, 893, 946, 967, 1104, 1341, 
        1428, 1606, 1651, 1670, 1746, 1782, 1882, 2229, 2341, 2439, 2640, 2646, 2893, 3014, 3037, 3154, 
        3185, 3216, 3290, 3550, 3796, 4006, 4303, 4311, 4404, 4460, 4550, 4952, 4966, 5025, 5375, 5412, 
        5413, 5464, 5557, 5836, 5868, 6024, 6122, 6326, 6335, 6340, 6525, 6570, 6626, 6774, 6794, 7088, 
        7151, 7207, 7301, 7339, 7502, 7508, 7562, 7593, 7800, 7866, 7982, 8068, 8156, 8195, 8201, 8211, 
        8229, 8253, 8254, 8320, 8381, 8411, 8443, 8486, 8551, 8906, 8929, 9059, 9098, 9114, 9127, 9146, 
        9569, 9704, 9760, 9792, 9806};
 
    /**
     * Konstruktor der Klasse Suchen
     */
    public Suchen()
    {
        for(int i=0;i<feld.length;i++)
        {
            feld[i] = (int)(Math.random() * 1000000);
        }
        int find = 100;
        int x = 0;
        int bereichklein = 0;
        int bereichgroß = feld2.length;
        boolean active = true;
        while(active){
            x = bereichklein + (bereichgroß - bereichklein)/2;
            if(feld2[x] == find){
                active = false;
            }
            if(bereichklein == bereichgroß){
                System.out.println("Es wurde kein Wert gefunden");
            }
            else{
                if(feld2[x] > find){
                    System.out.println("Der zu findende Wert ist kleiner als der Wert auf den x zeigt." + x + " "+ bereichklein + " " + bereichgroß);
                    if(bereichgroß == x){
                        System.out.println("Es wurde kein Wert gefunden");
                        active = false;
                    }
                    bereichgroß = x;
                }
                if(feld2[x] < find){
                    System.out.println("Der zu findende Wert ist größer als der Wert auf den x zeigt." + x + " "+ bereichklein + " " + bereichgroß);
                    if(bereichklein == x){
                        System.out.println("Es wurde kein Wert gefunden");
                        active = false;
                    }
                    bereichklein = x;
                }
            }
        }
        if(find == feld2[x]){
            System.out.println("Beendet mit" + feld2[x] + "der x wert dazu ist " + x );
        }
    }
 
}
← Back to timeline