因此,程序可以制作出我需要制作的形状。但是我似乎无法弄清楚代码中将其打印出@的位置。
public static void main(String[] args)
{
int n = 9;
for(int row = 0; row < n ; row++)
{
for(int col = 0; col < n ; col++)
{
if(row == 0 || col == 0 || row == n - 1 || col == n - 1)
System.out.print("*");
else if(row + col == n - 1 || row == col)
System.out.print("+");
else
System.out.print(" ");
}
System.out.println();
}
}
}
Insert a single
if
statement and anelse
to cover the four corners and the middle, like那给我