A Way For Learning

Program to find MODE

No comments
/*Program to find the mode from the given array of integers*/
public class CJ {
public static void main(String[] args) {
int arr[]={3,44,88,99,88,100,76,88,45,45,76,88};
int count=0;
int countMAx=0;
int modevalue=0;
for (int i=0;i<arr.length ;i++ ) {
count=0;
for (int j=0;j<arr.length ;j++ ) {
if (arr[i]==arr[j]) {
count++;
}
}
if(count>countMAx){
countMAx=count;
modevalue=arr[i];
}
}
System.out.println("Mode = "+ modevalue);
}
}

No comments :

Post a Comment