Pages

Minggu, 30 Oktober 2011

Sequential Search

Kelas Larik
package SequentialSearch;


public class Larik {
public static int sequential(int[] data, int cari) {
        for (int i = 0; i < data.length; i++) {

            if (cari == data[i]) {
                System.out.println("bilangan " + data[i] + " ketemu di index ke ");
                return (i + 1);
            }

        }
        System.out.println("bilangan tidak ketemu");
        return -1;
    }
}
  

Kelas Main
package SequentialSearch;

public class Main {

  
    public static void main(String[] args) {

       
        int bil[] = new int[6];
        bil[0] = 10;
        bil[1] = 20;
        bil[2] = 50;
        bil[3] = 40;
        bil[4] = 60;
        bil[5] = 70;

        System.out.println(Larik.sequential(bil, 10));

    }
}

   

0 komentar:

Posting Komentar