I can't get the median out. I want the median from the words. Having a hard time getting the value out of the for loop.
public class MedianWord {
static double medianWordLength(String words) {
String[] parts = words.split(" ");
int[] a;
double median = 0;
for (int i = 0; i < parts.length; i++) {
a = new int[parts[i].length()];
Arrays.sort(a);
if (a.length % 2 == 0) {
median = ((double) a[a.length / 2] + (double) a[a.length / 2 - 1]) / 2;
}
else
median = (double) a[a.length / 2];
}
return median;
}
}