Algs4-1.1.11编写一段代码,打印出一个二维布尔数组的内容

1.1.11编写一段代码,打印出一个二维布尔数组的内容。其中,使用*表示真,空格表示假。打印出行号和列号。
答:
public  class Test
{
    public static void main(String[] args)
    {
      //初始化数组,行列和为偶数时true,奇数时为false。
      int rowLen=6;
      int colLen=7;
      boolean[][] array=new boolean[rowLen][colLen];
      for (int row=0;row<rowLen;row++)
           for (int col=0;col<colLen;col++)
              array[row][col]=(row+col)%2==0;
      //打印列号
      StdOut.printf(" ");
      for (int col=0;col<colLen;col++)
          StdOut.printf("%d",col);
      StdOut.printf(" ");
      //打印行号与数组元素值
      for (int row=0;row<rowLen;row++)
      {
          StdOut.printf("%d",row);
           for (int col=0;col<colLen;col++)
           {
              if (array[row][col])
                 StdOut.printf("*");
              else
                  StdOut.printf(" ");
           }
          StdOut.printf(" ");
      }
     }//end main
}//end class
Algs4-1.1.11编写一段代码,打印出一个二维布尔数组的内容