Re: [Solved] 2d array help
Quote:
Originally Posted by
nweid1
Code:
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
board[rows][columns] = false;
}
}
Firstly it is not always possible that the user is going to input same number of rows and columns i.e. it can be a irregular 2-dimensional array, therefore
you cannot write your inner for-loop the way you have written. More better way is
Code:
for(int i=0; i< rows; i++)
{
for(int j=0; j<board[i].length; j++)
{
//code
}
}
Secondly as said previously by dragon you are accessing your array elements incorrectly inside the for loop, it has to be
instead of
Code:
board[rows][columns]
Re: [Solved] 2d array help
Quote:
Originally Posted by
Rameshwar Soni
Firstly it is not always possible that the user is going to input same number of rows and columns i.e. it can be a irregular 2-dimensional array, therefore
you cannot write your inner for-loop the way you have written. More better way is
It's called rugged array.
Re: [Solved] 2d array help
The question originally posted by user will not have the irregular 2 dimensional array. So the for-loops used by the original user will work but will fail
if he goes for irregular multi-dimensional array.
Quote:
Originally Posted by
diamonddragon
It's called rugged array.
Do you mean to say Jagged array, which is there in C-sharp?:)-: