zoukankan      html  css  js  c++  java
  • 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
    图片

  • 相关阅读:
    CSS 之 伪类及伪元素
    php使用strlen()判断中文汉字字符串长度
    代码评审
    Windows下获取本机IP地址方法介绍
    c++ windows 获取mac地址
    Windows编译安装OpenSSL
    visio studio2008 删除最近的项目
    Windows中杀死占用某个端口的进程
    apache日志文件太大的问题
    text段,data段,bss段,堆和栈
  • 原文地址:https://www.cnblogs.com/longjin2018/p/9848495.html
Copyright © 2011-2022 走看看