/* * Blobcheck skeleton. * * csci 210 * * This program counts the size of "blobs" in a 2-D array. The * program uses a recursive function countBlob, which takes as * parameter a grid cell and computes and returns how many cell are * filled around it. The program calls this function for each cell in * the grid. */ public class BlobCheck { //constants to set the values for which the grid is filled or empty private static final char EMPTY = '0'; private static final char FILLED = '1'; private static final char MARKED = '*'; //array to hold the grid of numbers private char grid[][] = { {EMPTY, EMPTY, EMPTY, FILLED, FILLED}, {EMPTY, EMPTY, EMPTY, FILLED, EMPTY}, {FILLED, FILLED, EMPTY, EMPTY, EMPTY}, {FILLED, FILLED, FILLED, EMPTY, FILLED}, {FILLED, FILLED, EMPTY, EMPTY, FILLED} }; //the dimensions of the grid private int nrows, ncols; // The constructor public BlobCheck(){ //set up the grid nrows = grid.length; ncols=grid[0].length; printGrid(); } void printGrid() { System.out.println("The grid is: "); for (int i=0; i< nrows; i++) { for (int j=0; j< ncols; j++) System.out.print( grid[i][j] + " " ); System.out.println(); } } //count blobs in a grid at each position (i, j) public void count() { // call countBlob with all possible locations System.out.println("Blob counts: "); for (int i=0; i