ini main nya atau program utamanya
import java.io.*;
public class data2utama {
static BufferedReader dataIn = new BufferedReader(new InputStreamReader( System.in) );
static int pil;
static String tekan ="";
public static void main(String[] args) throws IOException {
data2 myutama = new data2();
do {
System.out.println("Menu Utama");
System.out.println("1. Input Data");
System.out.println("2. Tampil Data");
System.out.println("3. Cari Data");
System.out.println("0. Keluar");
System.out.print("Pilihan Anda : ");
pil = Integer.parseInt(dataIn.readLine());
switch(pil) {
case 1 :myutama.tambah();break;
case 2 :myutama.tampil();break;
case 3 :myutama.cari();break;
case 0 : System.out.print("\nTerima Kasih...");System.exit(0);break;
default : System.out.print("Anda Salah memilih");
}
} while (pil != 0);
}
}
ini data kelassnya
import java.io.*;
public class data2 {
static BufferedReader dataIn = new BufferedReader(new InputStreamReader( System.in) );
static String data[] = new String[50];
static int jml,i;
static String dtcari="";
public static void tambah() throws IOException {
System.out.println("\nInput Data Array");
System.out.println("Masukan Jumlah Data : ");
jml = Integer.parseInt(dataIn.readLine());
for (i = 1; i <= jml;i++) { System.out.print("Masukan Data Ke "+i+ " : "); data[i] = dataIn.readLine(); } } public static void tampil() { System.out.println("\nTampil Larik di JAVA"); for (i = 1; i <= jml;i++) { System.out.println("Data Ke "+i+ " : "+data[i]); } } public static void cari() throws IOException { System.out.println("\nCari Data di JAVA"); System.out.println("Masukan Data yang di Cari : "); dtcari = dataIn.readLine(); for (i = 1; i <= jml;i++) { if (dtcari.equals(data[i])) { System.out.println("Data yang di cari Ada di Indeks ke : "+i); } } } }
Tidak ada komentar:
Posting Komentar