TwoDimMethods

TwoDimMethods - /This program contains all the two-dimensional/array processing methods given in the text public class TwoDimMethods cfw static

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
for (col = 0; col < matrix[0].length; col++)
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/17/2011 for the course COMP 2301 taught by Professor Staff during the Spring '10 term at Kennesaw.

Page1 / 3

TwoDimMethods - /This program contains all the two-dimensional/array processing methods given in the text public class TwoDimMethods cfw static

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online