Java中的方板 - 为什么结果不同?

时间:2016-10-25 20:41:21

标签: java

第一段代码只产生一列和一堆行。第二段代码产生5x5板。第一段代码出了什么问题。这可能是一件愚蠢而简单的事,但我找不到它。

int size = 5;    // size of the board
      for (int row = 1; row <= size; ++row) {  
         for (int col = 1; col <= size; ++col) {
             System.out.println("# ");
         }
          System.out.println();
      }




int height = 5;
        int width = 5;
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < width; j++) {
                System.out.print("# ");
            }
            System.out.println();
        }

1 个答案:

答案 0 :(得分:-1)

int size = 5;
for(int row=1;row<=size;++row)
{
    for (int col = 1; col <= size; ++col)
    {
        System.out.print("# ");
    }
    System.out.println();
}

int height = 5;
int width  = 5;

for(int i=0;i<height;i++)
{
    for (int j = 0; j < width; j++)
    {
        System.out.print("# ");
    }
    System.out.println();
}