编写一段代码,打印出一个二维布尔数组的内容。其中,使用*表示真,空格表示假。打印出行号和列号。
代码
public class Main {
public static void main(String[] args) {
boolean[][] a = { { true, false, true }, { false, true, false },
{ true, true, false } };
printBooleanMatrix(a);
}
public static void printBooleanMatrix(boolean[][] matirx){
for (int i = 0; i < matirx.length; i ++){
for (int j = 0; j < matirx[0].length; j ++){
System.out.print(matirx[i][j]?"*":"_");
}
System.out.println();
}
}
}
结果
*_*
_*_
**_