Menentukan Modus dengan Jeliot

import java.util.scaner.io.*;

public class modus{
public static void main(String[]args){
    int banyak;
    int data[];
    int temp;
    int jumlah = 0;

    System.out.print("Banyaknya data : ");
    banyak =Input.nextInt();
    data = new int[banyak];
    for(int i=0;i<=banyak-1;i++){
        System.out.print("Data ke-"+(i+1)+": ");
        data[i]=Input.nextInt();
    }
    
    System.out.print("Data sudah diurut : ");
    for(int i=0; i<=banyak-1; i++) {
        System.out.print(data[i]+" ");
        jumlah=jumlah + data[i];
    }

    int hasil=0;
    int besar=0;
    for (int i=0; i<data.length ;i++){
        if(data[i]==banyak){
        System.out.print(data[i]+" ");
        System.out.print(++temp);
            if(temp>besar){
                besar=temp;
                hasil=banyak;
            }
        }
        else{
            banyak=data[i];
            temp=1;
            System.out.print(data[i]+" ");
            System.out.print(temp);
            }
        }
        System.out.print("Modus ="+hasil);
    }
}

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