Please delete one of your questions, you made two almost identical questions..
import java.util.Arrays;
public class Median {
public static void main(String[] args) {
int[][] array2d = {
{1, 4, 3, 2, 5},
{4, 5, 3, 2, 9},
{4, 7, 8, 98, 24}
};
// Create a new list to store the items
int[] list = new int[array2d.length*array2d[0].length];
// keep track of where we are.
int listPos = 0;
// iterate over the entire 2d array adding each integer
for(int i = 0 ; i < array2d.length; i++) {
for(int j = 0; j < array2d.length; j++) {
list[listPos++] = array2d[i][j];
}
}
// sort the list.
Arrays.sort(list);
System.out.println(median(list));
}
/**
* Finds the median in an Array of integers.
* @param m Array of integers
* @return the median value
*/
public static double median(int[] m) {
int middle = m.length/2;
if (m.length%2 == 1) {
return m[middle];
} else {
return (m[middle-1] + m[middle]) / 2.0;
}
}
}