Program mencari data pada Array menggunakan sequential Search

import java.io.*;
class tugasModul6
{
public static void main (String args []) throws Exception
{
int pilih = 0;
BufferedReader inputan = new BufferedReader (new InputStreamReader(System.in));
String [][] data = new String [100][100];
String ulang = “”;

while (true)
{

System.out.println(“\tMENU”);
System.out.print(“=====================\n”);
System.out.println(“1. Input Data”);
System.out.println(“2. Pencarian Data”);
System.out.println(“3. Keluar”);
System.out.print(“=====================\n”);
System.out.print(“Masukkan Pilihan Anda :”);
pilih = Integer.parseInt(inputan.readLine());

switch (pilih)
{

case 3 : System.exit(0);
case 1 :

for (int i=0;;i++)
{

System.out.print(“Masukkan Kode Barang : “);
data [i][0]  = inputan.readLine();
if (data [i][0].equals(“/”)) break;

else
{

System.out.print(“Masukkan Nama Barang : “);
data [i][1] = inputan.readLine();
System.out.print(“Masukkan Jumlah Barang : “);
data [i][2] = inputan.readLine();
System.out.print(“Masukkan Harga Barang : “);
data [i][3] = inputan.readLine();
System.out.println();

}

}

break;

case 2 :

System.out.print(“Masukkan kode barang yang ingin anda cari: “);
String cari = inputan.readLine();

for (int i=0;i<100;i++)
{
if (cari.equals(data [i][0]))
{
System.out.print(“====================================”);
System.out.print(“Kode Barang\t : “+data[i][0]+”\n”);
System.out.print(“Nama Barang\t : “+data[i][1]+”\n”);
System.out.print(“Jumlah Barang\t : “+data[i][2]+”\n”);
System.out.print(“Harga Barang\t : “+data[i][3]+”\n”);
System.out.print(“====================================”);
break;
}

else System.out.println(“Data Tidak Ditemukan”);
}
break;
default : System.out.print(“Pilihan Tidak Ada /n”);

}
}
}
}

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: