// 输出以下菱形
// *
// * *
// * *
// * *
// * *
// * *
// *
int u = 4;
for (int x = 1; x <= u; x++)
{
for (int j = 1; j <= (u - x); j++)
{
System.out.print(" ");
}
for (int j = 1; j <= 2 * x - 1; j++)
{
if (j == 1 || j == 2 * x - 1)
{
System.out.print("*");
} else
{
System.out.print(" ");
}
}
System.out.println();
}
for (int x = 1; x <= u - 1; x++)
{
for (int j = 1; j <= x; j++)
{
System.out.print(" ");
}
for (int j = 1; j <= 2 * (u - x) - 1; j++)
{
if (j == 1 || j == 2 * (u - x) - 1)
{
System.out.print("*");
} else
{
System.out.print(" ");
}
}
System.out.println();
}
空心菱形
最新推荐文章于 2022-08-29 23:00:27 发布