Friday, February 24, 2012

program modus

import jeliot.io.*;

public class Modus {
    public static void main(String[] args) {
        int a[]={2,2,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5,5,5};
        int c=a[0];
        int b=0;
        int hasil=0,besar=0;
        for (int i=0; i<a.length ;i++){
            if(a[i]==c){
                System.out.print(a[i]+" ");
                System.out.println(++b);
                    if(b>besar){
                    besar=b;
                    hasil=c;
                    }
            }else{
                c=a[i];
                b=1;
                System.out.print(a[i]+" ");
                System.out.println(b);
            }
        }
        System.out.println("Modus = "+hasil);
    }
}

No comments:

Post a Comment