获取游戏的平均块数

问题描述 投票:-1回答:1

我刚接触Java编码。我需要计算电路板上每列的平均块数。以下是计算板上所有列中的块总数,然后除以列数。

这是我到目前为止,但我认为这是不对的。我觉得我错过了什么。

public int getAverageColumnBlocks(Board board)
{
    int avgColumnBlock = 0;
    for (int col = 0; col < Board.WIDTH; col++)
     {
      for (int row = 0; row < Board.HEIGHT; row++)
       {
          if(board.isBlockAt(col, row))
             {
                avgColumnBlock++;
             }
       }
     }
    return avgColumnBlock;  
}
java
1个回答
0
投票
public int getAverageColumnBlocks(Board board)
{
    int total = 0;
    for (int col = 0; col < Board.WIDTH; col++)
     {

      for (int row = 0; row < Board.HEIGHT; row++)
       {
          if(board.isBlockAt(col, row))
             {
                total++;
             }
       }

     }
    return total/Board.WIDTH;  
}
© www.soinside.com 2019 - 2024. All rights reserved.