Beranda > Java Tutorial, Sinaung > Mencari Data Array dengan Sequencial Search

Mencari Data Array dengan Sequencial Search


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”);

}
}}}

Sumber: http://stikomksi2007azwar.wordpress.com/2008/08/24/program-mencari-data-pada-array-menggunakan-sequential-search-3/

  1. Belum ada komentar.
  1. No trackbacks yet.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: