我的作业是
我想出了以下内容,我该如何压缩它?
public class HW8 {
public static void main(String[] args)
{
char [][] gameBoard = new char[20][20];
int x = 0;
int y = 0;
char[][] a = new char[x][y];
char[][] gliderArrays = glider(a);
for (int r = 0; r < a.length; r++)
{
for (int c = 0; c < a[0].length; c++)
{
gliderArrays[r][c] = a[r][c];
}
}
for (int i = 0; i < gliderArrays.length; i++)
{
for (int j = 0; j < gliderArrays[0].length; j++)
{
gameBoard[i][j] = gliderArrays[i][j];
gameBoard[2][2] = gliderArrays[i][j];
}
}
for (int i = 0; i < gameBoard.length; i++) {
for (int j = 0; j < gameBoard[0].length; j++) {
System.out.print(gameBoard[i][j]);
}
System.out.println();
}
}
//Create the glider 2D array
public static char[][] glider(char[][] a) {
char[][] gliderArray = {{' ','*',' '},
{' ','*','*'},
{'*',' ','*'}};
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a[0].length; j++) {
gliderArray[i][j] = a[i][j];
}
}
return gliderArray;
}
}