-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsome_example_week5.java
More file actions
32 lines (29 loc) · 954 Bytes
/
some_example_week5.java
File metadata and controls
32 lines (29 loc) · 954 Bytes
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
import java.util.*;
public class NewClass {
public static void main(String[] args) {
int[][] a = { { -34, 2, 8, 3, 5, 9, 6, 7, 3 },
{ 3, 1, 55, 2, 1, 5, 9, 3, 0 },
{ 2, 2, 181, 8, 6, 2, 5, 1, 4 }
};
System.out.println("Printed with deepToString:");
System.out.println(Arrays.deepToString(a));
System.out.println("And printed with an even-better printArray:");
printArray(a);
}
// even better version!
public static void printArray(int[][] a) {
int rows = a.length;
int cols = a[0].length;
System.out.print("[ ");
for (int row=0; row<rows; row++) {
if (row > 0) System.out.print(" ");
System.out.print("[");
for (int col=0; col<cols; col++) {
if (col > 0) System.out.print(", ");
System.out.format("%3d",a[row][col]); // field-width = 3
}
System.out.println("]");
}
System.out.println("]");
}
}