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 “);}

}

}

}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: