Beranda > Java Tutorial, Sinaung > Metode pencarian Sequential Search di Java

Metode pencarian Sequential Search di Java


// metoda pencarian menggunakan sequential search

class sequential_search{
public static void main(String[]args) throws Exception {

int a[] = new int[4];
int x,i,posisi;
boolean ada;

a[0] = 2;
a[1] = 62;
a[2] = 32;
a[3] = 42;

ada = false;
posisi = 0;

x = 32;

for (i=0; i<=3; i++){

if (a[i] == x) {
ada = true;

if (ada== true){
System.out.print(” ketemu posisi ” + (i+1));
}
else{System.out.print(” tidak ada “);}

}

}

}
}

Sumber: http://stikomksi2007azwar.wordpress.com/2008/01/05/metode-pencarian-sequential-search-di-java/

  1. Belum ada komentar.
  1. No trackbacks yet.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: