{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

TwoDimMethods

# TwoDimMethods - /This program contains all the...

This preview shows pages 1–3. Sign up to view the full content.

4 //This program contains all the two-dimensional //array processing methods given in the text. / public class TwoDimMethods { static final int rows = 5; //this can be set to any number static final int columns = 5; //this can be set to any number public static void main(String[] args) { int[][] board ={{23,5,6,15,18}, {4,16,24,67,10}, {12,54,23,76,11}, {1,12,34,22,8}, {81,54,32,67,33}}; printMatrix(board); sumRows(board); largestinRows(board); } public static void printMatrix(int[][] matrix) { int row, col; for (row = 0; row < matrix.length; row++) { for (col = 0; col < matrix[row].length; col++) System.out.printf("%7d", matrix[row][col]); System.out.println(); } } public static void sumRows(int[][] matrix) { int row, col; int sum; //sum of each individual row for (row = 0; row < matrix.length; row++) { sum = 0; for (col = 0; col < matrix[row].length; col++) sum = sum + matrix[row][col]; System.out.println("The sum of the elements of row " + (row + 1) + " = " + sum); } } public static void sumColumns(int[][] matrix) { int row, col; int sum; //sum of each individual column

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
for (col = 0; col < matrix[0].length; col++) { sum = 0; for (row = 0; row < matrix.length; row++) sum = sum + matrix[row][col]; System.out.println("The sum of the elements of column "
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern