所以我觉得代码已经完成并且可以运行了,但是我在基础方面遇到了麻烦,完全忘记了在哪里放置 main 方法以及在其中放置什么。我的课叫做“Cell”,里面有一些方法等,现在我想运行它,对不起,如果我没有提供足够的细节,希望大家能理解。代码:
public class Cell {
//We need an array for the cells and one for the rules.
public int[] cells = new int[9];
public int[] ruleset = {0,1,0,1,1,0,1,0};
//Compute the next generation.
public void generate()
{
//All cells start with state 0, except the center cell has state 1.
for (int i = 0; i < cells.length; i++)
{
cells[i] = 0;
}
cells[cells.length/2] = 1;
int[] nextgen = new int[cells.length];
for (int i = 1; i < cells.length-1; i++)
{
int left = cells[i-1];
int me = cells[i];
int right = cells[i+1];
nextgen[i] = rules(left, me, right);
}
cells = nextgen;
}
//Look up a new state from the ruleset.
public int rules (int a, int b, int c)
{
if (a == 1 && b == 1 && c == 1) return ruleset[0];
else if (a == 1 && b == 1 && c == 0) return ruleset[1];
else if (a == 1 && b == 0 && c == 1) return ruleset[2];
else if (a == 1 && b == 0 && c == 0) return ruleset[3];
else if (a == 0 && b == 1 && c == 1) return ruleset[4];
else if (a == 0 && b == 1 && c == 0) return ruleset[5];
else if (a == 0 && b == 0 && c == 1) return ruleset[6];
else if (a == 0 && b == 0 && c == 0) return ruleset[7];
return 0;
}{
}
}