I was wondering if it was possible to find the median value of an array? For example, suppose I have an array of size nine. Would it possible to find the middle slot of this
In the case of Java, dividing by 2.0 is enough to cast int to double:
2.0
int
double
return n%2 == 0 ? (all[n/2] + all[n/2-1])/2.0 : all[(n-1)/2];
The first condition checks if the value is even.