October 17, 2017

Find Mean Mode and Median in Java : Introduction to Data Science

import java.util.Arrays;

/**
 * Introduction to Data science
 * Finding Mean Mode and Median
 */

/**
 * @author belazy
 * Consumerfed triveni supermarket kozhikode
 *
 */
public class DataScienceLessonOne {

Integer[] arraySample = {4,5,3,3,5,6,7,3,1,5};

/**
* @param args
*/
public static void main(String[] args) {

DataScienceLessonOne dataScience = new DataScienceLessonOne();
System.out.println(dataScience.findMean());
System.out.println(dataScience.findMedian());
System.out.println(dataScience.findMode());

}

private char[] findMode() {
// TODO Auto-generated method stub
return null;
}

private float findMedian() {
// TODO Auto-generated method stub
float median = 0;
Arrays.sort(arraySample);

median = (arraySample.length % 2) == 0 ? (arraySample[arraySample.length/2]+arraySample[(arraySample.length/2)-1])/2 :arraySample[arraySample.length/2];


return median;
}

private float findMean() {
int sum = 0;
float mean = 0;
for(int a:arraySample){
sum = sum +a;
mean = sum/arraySample.length;
}
return mean;
}

}

No comments:

Post a Comment

Your feedback may help others !!!

Facebook comments