Having two java files one a class the other a driver how do you find the smalles
ID: 3640920 • Letter: H
Question
Having two java files one a class the other a driver how do you find the smallest value of the arrays and also calculate the total in column?pretty much how do you
calculateTotalCol() FindSmallestValue()
---------------------------
The Class:
// This class contains methods to process elements in two-
// dimensional arrays.
public class TwoDimArraysMethods
{
public static void printMatrix(int[][] matrix)
{
for (int row = 0; row < matrix.length; row++)
{
for (int col = 0; col < matrix[row].length; col++)
System.out.printf("%7d", matrix[row][col]);
System.out.println();
}
} //end printMatrix
public static void sumRows(int[][] matrix)
{
int sum;
//sum of each individual row
for (int row = 0; row < matrix.length; row++)
{
sum = 0;
for (int 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 + ".");
}
} //end sumRows
public static void largestInRows(int[][] matrix)
{
int largest;
//Largest element in each row
for (int row = 0; row < matrix.length; row++)
{
largest = matrix[row][0]; //assume that the first
//element of the row is
//largest
for (int 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 + ".");
}
}
}
======================================================================
The Driver:
// This program illustrates how two-dimensional arrays are
// passed as parameters to methods.
public class TwoDimArraysAsParam //Line 1
{ //Line 2
public static void main(String[] args) //Line 3
{ //Line 4
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 5
TwoDimArraysMethods.printMatrix(board); //Line 6
System.out.println(); //Line 7
TwoDimArraysMethods.sumRows(board); //Line 8
System.out.println(); //Line 9
TwoDimArraysMethods.largestInRows(board); //Line 10
} //end main
}
====================================================