-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTwo_Dimensional1111.java
33 lines (30 loc) · 1.08 KB
/
Two_Dimensional1111.java
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
/**
* Write a code fragment that prints the contents of a two-dimensional boolean
* array, using * to represent true and a space to represent false. Include row and column
* numbers.
*/
public class Two_Dimensional1111 {
public static void printBooleanArray(boolean[][] array) {
for (int i = 0; i < array.length; i++) {
//Print row numbers
System.out.print(i + ": ");
for (int j = 0; j < array[i].length; j++) {
System.out.print(array[i][j] ? '*' : ' ');
System.out.print(" ");
}
System.out.println();
}
//Print column numbers at bottom
System.out.println(" ");
for (int j = 0; j < array[0].length; j++) {
System.out.print(j + " ");
}
System.out.println();
}
public static void main(String[] args) {
boolean[][] exampleArray = {
{true, false, true, false}, {false, true, false, true}, {true, true, false, false}, {false, false, true, false}
};
printBooleanArray(exampleArray);
}
}