Java 需要添加5“@&引用;符号。每个角落有4个,中间有一个
所以这个程序制作了我需要的形状。但我似乎不知道在代码中的什么地方可以打印出@Java 需要添加5“@&引用;符号。每个角落有4个,中间有一个,java,Java,所以这个程序制作了我需要的形状。但我似乎不知道在代码中的什么地方可以打印出@ 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)
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();
}
}
}
publicstaticvoidmain(字符串[]args)
{
int n=9;
对于(int行=0;行
插入一个if
语句和一个else
语句,覆盖四个角和中间,如
int n = 9;
for (int row = 0; row < n; row++) {
for (int col = 0; col < n; col++) {
if ((row == 0 || row == n - 1) && (col == 0 || col == n - 1)
|| (row == col && col == n / 2))
System.out.print("@");
else 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();
}
@Richard编辑您的问题以包含所需的输出。特别是如果它与我发布的内容不同。这应该和你得到的完全一样。我没有做任何花哨的事情,只是添加了你指定的五个条件。
@*******@
*+ +*
* + + *
* + + *
* @ *
* + + *
* + + *
*+ +*
@*******@