Kamis, 14 Juni 2012

JAVA SEARCHING

package SEARCHING;
import java.util.*;

public class Main {

public static void main(String[] args) {
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 sudah melwbihi batas ndeks array
System.out.print("Data Tidak Ada");
}
}

Tidak ada komentar:

Posting Komentar