我正在从事一个名为 life 的项目,该项目应该随机显示 1 表示活着或 0 表示死亡。当我执行程序时,零和一继续打印。我查看了代码,我找不到错误。
public class Life {
//Makes the first batch of cells
public static boolean firstgen(boolean[][] a)
{
int N = 5;
double cellmaker = Math.random();
//boolean[][] b = new boolean[N][N];
for (int i = 0; i < N; i++)
{
for (int j= 0; j< N;j++)
{
if (cellmaker >0.5)
{
a[i][j]= true;
return true;
}
else
a[i][j]=false;
}
}
return false;
}
public static void main(String[] args)
{
boolean[][] b = new boolean[5][5];
//Placing the cells
for (int i =0;i < 5; i++)
{
for (int j= 0 ; j < 5;i++)
{
if (firstgen(b)== true)
{
System.out.print("1"); //1 is live cell
}
else
System.out.print("0");// 0 is dead cell
}
System.out.println();
}
}
}