public class Ragged { public static double colAvg (int[][] a, int c) { double sum=0; int count=0; for (int r=0; r c) { sum+=a[r][c]; count++; } return sum/count; } // colAvg public static void display2Darray(int[][] a) { for (int[] row: a) { if (row != null) if (row.length == 0) System.out.print("empty"); else for (double d: row) System.out.print(d+"\t"); else System.out.print("null"); System.out.println(); } // for } // display2Darray public static void main(String[] args) { int[][] m = new int[5][]; int[] m0 = {2, 5, 7, 9, 6}; m[0] = m0; int[] m2 = {8, 6, 4}; m[2] = m2; int[] m3 = {15, 25,35, 45, 65, 75, 85}; m[3] = m3; int[] m4 = {}; m[4] = m4; display2Darray(m); System.out.println("Average of col 0 "+colAvg(m, 0)); System.out.println("Average of col 1 "+colAvg(m, 1)); System.out.println("Average of col 3 "+colAvg(m, 3)); System.out.println("Average of col 5 "+colAvg(m, 5)); } }