0

I'm writing Conway's game of life for a school assignment. I have a text file with coordinates of the initial locations with bacterium. All I need to know is how to tell java to compare a coordinate in the matrix to a coordinate from the file. The pairs are listed in the file like this:
1 3

1 7

1 8

1 11 etc.
I tried

in = new Scanner(new File("/home/chris/Desktop/life100.txt"));
   for(int i = 0; i < grid.length; i++){
	for(int j = 0; j < grid[i].length; j++){
		if(grid[i][j] == in.nextInt() in.nextInt()){
                     grid[i][j] = '*';
		}
	}

But I have no idea how format my if statement

1
Contributor
2
Replies
3
Views
7 Years
Discussion Span
Last Post by cwpent
0

I thought i'd try a different approach

in = new Scanner(new File("/home/chris/Desktop/life100.txt"));
   while(in.hasNext()){
   grid[in.nextInt()][in.nextInt()] = '*';
    }

But this gives me the error "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 100" which doesn't make any sense, because my array is 20 x 20 and im only putting in 100 points.

0

The file had 1-20 instead of 0-19. Problems solved.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.