I'm trying to output a square of X's using an array. The diagonals of the square will be filled with 'X' and the empties will be filled with spaces '_'.
Here's the code I got:
public static char[][] square(int z) {
int size=5;
char[][] myArr = new char[size][size];
for (int c=0;c<size;c++)
myArr[c][c]='X';
for (int r=0;r<size;r++)
{
for (int col=size-1;col>=0;col--)//put X
{
myArr[r][col]='X';
}
}
for(int count=0;count<size;count++){
if (myArr[count][count]!='X')
myArr[count][count]=' ';
}
return myArr;
}
This should be working-I ran it manually on paper and everything should have been fine. What can the problem be?