-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwoDimMethods.java
More file actions
36 lines (33 loc) · 1.08 KB
/
TwoDimMethods.java
File metadata and controls
36 lines (33 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package unit_06.Examples.Example_14;
public class TwoDimMethods {
public static void printMatrix(int[][] matrix) {
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[i].length; j++) {
System.out.printf("%7d", matrix[i][j]);
}
System.out.println();
}
}
public static void sumRows(int[][] matrix) {
int sum;
for (int i = 0; i < matrix.length; i++) {
sum = 0;
for (int j = 0; j < matrix[i].length; j++) {
sum += matrix[i][j];
}
System.out.println("sum[" + i + "] = " + sum);
}
}
public static void largestInRows(int[][] matrix) {
int largest;
for (int i = 0; i < matrix.length; i++) {
largest = matrix[i][0];
for (int j = 0; j < matrix[i].length; j++) {
if (largest < matrix[i][j]) {
largest = matrix[i][j];
}
}
System.out.println("Largest number in row[" + i + "] = " + largest);
}
}
}