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

Recommended Answers

All 3 Replies

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"
  }
}

Or you could use the enhanced for loop:

for (char gridRow[] : grid) 
    for(char val: gridRow)
    {
	//do stuff with val
    }

thanks guys

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.