Java 如何让printToScreenNew()方法打印新一代?我得到的结果是我的包名后跟Generation@33909752 因为您没有在类中重写toString(),所以它从Object继承了此方法,从而继承了结果。因为您没有在类中重写toString()
如何让printToScreenNew()方法打印新一代?我得到的结果是我的包名后跟Generation@33909752Java 如何让printToScreenNew()方法打印新一代?我得到的结果是我的包名后跟Generation@33909752 因为您没有在类中重写toString(),所以它从Object继承了此方法,从而继承了结果。因为您没有在类中重写toString(),java,Java,如何让printToScreenNew()方法打印新一代?我得到的结果是我的包名后跟Generation@33909752 因为您没有在类中重写toString(),所以它从Object继承了此方法,从而继承了结果。因为您没有在类中重写toString(),所以它从Object继承了此方法,从而继承了结果。 public Generation newGen() { Generation newGen = new Generation(); for (int i = 1; i &
因为您没有在类中重写
toString()
,所以它从Object
继承了此方法,从而继承了结果。因为您没有在类中重写toString()
,所以它从Object
继承了此方法,从而继承了结果。
public Generation newGen() {
Generation newGen = new Generation();
for (int i = 1; i < 26; i++) {
for (int j = 1; j < 76; j++) {
int x = i;
int y = j;
int n = numberOfNeighbors(x, y);
if (gen[i][j] == 'X') {
if (n == 2 || n == 3) {
newGen.gen[i][j] = 'X';
}
if (n != 2 || n != 3) {
newGen.gen[i][j] = '.';
}
}
if (gen[i][j] == '.') {
if (n == 3) {
newGen.gen[i][j] = 'X';
}
if (n != 3) {
newGen.gen[i][j] = '.';
}
}
}
}
return newGen;
}
public void printToScreenNew() {
Generation newGen = newGen();
System.out.print(newGen.toString());
System.out.println("\n");
}