public class Pass2Darray{ public static void main(String[] args) { int[][] numbers = {{1,2,3,4}, {5,6,7,8},{9,10,11,12}}; System.out.println("Here are the values in the array"); showArray(numbers); System.out.println("Here are the sum of rows in the array"); showSumRows(numbers); System.out.println("Here are the sum of the columns in the array"); showSumColumns(numbers); System.out.println("The sum of the values is " + arraySum(numbers)); } private static void showArray(int[][] array) { for (int row = 0; row < array.length; row++) { for (int col = 0; col < array[row].length; col++) { System.out.print(array[row][col] + " "); } System.out.println(); } } private static int arraySum(int[][] array) { int total = 0; for (int row = 0; row < array.length; row++) { for (int col = 0; col < array[row].length; col++) { total += array[row][col]; } } return total; } private static void showSumRows(int[][] array) { int total = 0; for (int row = 0; row < array.length; row++) { for (int col = 0; col < array[row].length; col++) { total += array[row][col]; } System.out.println(total); total = 0; } } private static void showSumColumns(int[][] array) { int total = 0; for (int col = 0; col < array[0].length; col++) { for (int row = 0; row < array.length; row++) { total += array[row][col]; } System.out.println(total); total = 0; } } }