Coding Searching

Bagi teman-teman yng membutuhkan coding buat Searching ini coding nya......

ocey,,,,,,,,,,,,,,,,

import javax.swing.JOptionPane;

public class searching2 {
    int[] dataArray = new int [100];
    int cari;
    int batas;
    int [] hasil = new int [100];

    public void isiAray(){
        System.out.println("==================================");
        System.out.println("==========Isi Data Array==========");
        System.out.println("==================================");
        System.out.println();
        String input = JOptionPane.showInputDialog("Masukkan Banyak data");
        System.out.println();
        batas = Integer.parseInt(input);
        System.out.println("Banyak data = "+ batas);
        for (int i = 0; i
            String start = JOptionPane.showInputDialog("Data "+(i+1)+ "");
            dataArray [i] = Integer.parseInt(start);
            System.out.println();
            System.out.println("Data "+" "+(i+1)+"= " + dataArray [i]);
        }
    }

    public void Input(){
        String str = JOptionPane.showInputDialog("Data yang dicari :");
        cari = Integer.parseInt(str);
        System.out.println();
        System.out.println("Data yang dicari :"+cari);
    }

    public void search (){
        int x = 0;
        for (int i =0; i
            if (cari == dataArray [i]){
                hasil [x] = i;
            }
        }

        for (x = 0; x
            if (hasil [x]!=0){
                System.out.println();
                System.out.println();
                System.out.println("Data " + cari + "ada pada posisi " + (hasil [x]+1));

            }        }    }

    public static void main (String[] args){
        searching2 o1 = new searching2();

        o1.isiAray();
        o1.Input();
        o1.search();
    }  }

0 comments:

Posting Komentar