Monday, November 22, 2010

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

2 comments:

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

    ReplyDelete
  2. yg jelas beda vendor. jbuilder punyanya borland, netbeans punyanya netbeans.org. ada beberapa diskusi ttg hal tsb. cek these links:
    http://www.indicthreads.com/1513/java-ides-netbeans-vs-eclipse-vs-jdeveloper/
    http://vanma-qu.blogspot.com/2007/07/jbuilder-vs-eclipse-vs-netbeans.html
    http://www.diskusiweb.com/viewthread.php?tid=4281

    ReplyDelete