What time is it?


Pages

This is default featured slide 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Kamis, 22 September 2011

Script Algoritma Grouping Data

Hoho, seorang sahabat bertanya tentang bagaimana flowchart dari pengelompokan data angka yang kita entrikan..
Setelah berusaha cukup lama, akhirnya berhasil menemukan caranya yang saya tulis dalam bahasa Java.

class CobaGrouping2{
    public static void main(String []args){
        //static array dan inisialisasi
        int a[]=new int[6];
        a[0]= 1;
        a[1]= 1;
        a[2]= 1;
        a[3]= 2;
        a[4]= 3;
        a[5]= 3;
       
        int b[][]= new int[6][2];      //untuk menyimpan hasil pengelompokkan data
        int indexb=0;                     // indexb untuk counter baris pada array 2 dimensi b
        int kategori = a[0];            // inisialisasi kategori untuk yang pertama sama dengan data awal pada array
        int count=1;                      //dengan asumsi kategori yang dicatat menandakan ada 1 data
        for(int i=1;i<6;i++){
            //diatas index 0
                if(a[i] == kategori){
                    count++;
                }else{    //jika tidak sama
                    b[indexb][0]=kategori;
                    b[indexb][1]=count;
                    indexb++;
                    kategori=a[i];     //menyimpan nilai kategori yang baru sama dengan data terakhir yang diperiksa
                    count=1;
                }
        }
        
        //script untuk menampilkan
        for (int c=0; c<6; c++){
            for (int d=0;d<2;d++){
                System.out.print (b[c][d]);
            }
            System.out.println();
        }
    }
}   
   
script diatas hanya bisa dipakai jika data dalam array sudah diurutkan.
terima kasih, semoga bisa membantu dan jadi referensi