{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

TwoDimArraysAsParam

# TwoDimArraysAsParam - sum = 0 for(col = 0 col<...

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

//TwoDimArraysAsParam public class TwoDimArraysAsParam { 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}, {12,34,76,78,9}}; //Line 1 printMatrix(board); //Line 2 System.out.println(); //Line 3 sumRows(board); //Line 4 System.out.println(); //Line 5 largestinRows(board); //Line 6 } 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++)

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { 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 largestinRows(int matrix) { int row, col; int largest; //Largest element in each row for (row = 0; row < matrix.length; row++) { largest = matrix[row][0]; //assume that the first //element of the row is //largest for (col = 1; col < matrix[row].length; col++) if (largest < matrix[row][col]) largest = matrix[row][col]; System.out.println("The largest element of row " + (row + 1) + " = " + largest); } } }...
View Full 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