Contoh Program Java: Pencarian pada Array


import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO code application logic here
Scanner sc = new Scanner(System.in);
int [] x = new int[10];
for(int j=0; j<10; j++)
{
System.out.print("Masukkan data = ");
x[j] = sc.nextInt();
}
for (int i=0; i<=9; i++)
System.out.println(x[i]);
int cari;
System.out.print("Cari data = ");
cari = sc.nextInt();
int k;
for(k=0; k<10; k++)
if (cari == x[k])
{
System.out.println("Data ditemukan");
break; //hentikan perulangan
}
if (k == 10) //pencarian sdh melebihi batas indeks array
System.out.println("Data tidak ada");
}
}

4 Responses to Contoh Program Java: Pencarian pada Array

  1. Ass,, Pak boleh dijelasin g Pak perbedaan antara JBuilder dengan NetBeans??
    terima kasih Pak,,

  2. Bara Farizal Isnaro says:

    Ehm…

  3. achmad says:

    Mkasih buat programnya, sangat membantu.🙂

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: