0

lets say i have a grid----->grid[10][10]
i want to scan the grid for a char 's' what should I do
should I...
do a enhanced for loop and how can any show a example

3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by ilovejava
1

The code portion below is showing how to access a 2 dimension array...

// assume that your "grid" variable is type int
for (int row=0; row<grid.length; row++) {
  for (int column=0; column<grid[row].length; column++) {  // could simply use grid[0].length
    int value = grid[row][column]  // accessing the "grid" variable at "row" and "column"
  }
}

Edited by Taywin: n/a

1

Or you could use the enhanced for loop:

for (char gridRow[] : grid) 
    for(char val: gridRow)
    {
	//do stuff with val
    }
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.