If I have a 2d array like:
boolean[][] map = new boolean[50][50];
How can I set the outer edge of booleans to true only in a loop?
So, for the following array:
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
You would have:
1 1 1 1 1 1
1 0 0 0 0 1
1 0 0 0 0 1
1 0 0 0 0 1
1 1 1 1 1 1
I'm new to programming and I've been struggling to get this to work?
I thought possibly using 2 loops like:
for(int i = 0; i < map.length; i++)
{
map[i][0] = true;
map[i][map[0].length] = true;
}
for(int i = 0; i < map[0].length; i++)
{
map[0][i] = true;
map[map.length][i] = true;
}
But honestly I'm not sure if this is the correct approach?