I hope you all are doing well, so the problem I guess is in understanding the difference between those two codes:
first code (filling multidim-array with enhanced for loop) - does not work
static char[][] battleBoard = new char[10][10];
public static void main(String[] args)
{
for(char[] rows:battleBoard)
{
for(char column:rows)
{
column = '*';
}
}
}
if we tried to print-out the array (expecting '*' to be assigned to each element in the array) using the following code - we fail (i.e it is still empty)!
for(int i=0;i<battleBoard.length;i++)
{
for(int j=0; j<battleBoard[i].length; j++)
{
System.out.print("|" + battleBoard[i][j] + "|");
}
System.out.println();
}
But on the other hand we have(it works fine when printed):
static char[][] battleBoard = new char[10][10];
public static void main(String[] args)
{
for(char[] rows:battleBoard)
{
Arrays.fill(rows, '*');
}
So the question is: does not column, rows in the previous code-blocks stand for new variables - i.e Arrays.fill(rows,'*') shouldn't have met the need cause it fills ((rows char array)) but not ((battleBoard char array)) ;
Thx in advance for helping me out!