0

Hey folks,

Basically, I am trying to recreate Conway's Game of Life in java. I'm getting input from a file and using it as the first generation. I set up my array and have input working correctly. However, when I'm trying to use a method evaluate my array at certain indexes to determine whether the point is alive or not, it doesn't seem to recognize the array declared earlier in the same class. I'm sure this is very simple, but if anybody can tell me how to correct this it would be much appreciated.

Each of the 8 'if' statements in the last method produce an error, where b[][] cannot be found in the class life....

```
import java.util.*;
import java.io.*;
public class life{
public static void main(String[] args) throws IOException {
java.io.File file = new java.io.File("desktop/input.txt");
Scanner input = new Scanner(file);
try {
int rows= input.nextInt();
int columns = input.nextInt();
char[][] b = new char[rows][columns];
char[][] temp = new char[rows][columns];
for (int i=0; i< rows; i++) {
String aLine = input.next();
for (int j=0; j<columns; j++) {
b[i][j]=aLine.charAt(j);
if (j == (columns-1))
System.out.println(b[i][j]);
else
System.out.print(b[i][j]);
}
}
}
catch (Exception e) {
}
}
public static int getAlive( int i, int j ) {
int result = 0;
try {
if (b[(i-1)][(j-1)] == 'X')
result ++;
if (b[(i-1)][(j)] == 'X')
result ++;
if (b[(i-1)][(j+1)] == 'X')
result ++;
if (b[(i)][(j-1)] == 'X')
result ++;
if (b[(i)][(j+1)] == 'X')
result ++;
if (b[(i+1)][(j-1)] == 'X')
result ++;
if (b[(i+1)][(j)] == 'X')
result ++;
if (b[(i+1)][(j+1)] == 'X')
result ++;
return result;
}
catch (RuntimeException ex){
}
}
}
```

*Edited 4 Years Ago by Dani*: Fixed code formatting