我一直在尝试使用java中的for循环语句打印不同的模式.现在我想学习如何打印以下模式.它基本上是一种倾斜的金字塔型图案.
*
**
***
****
***
**
*
Run Code Online (Sandbox Code Playgroud)
我试图制作它并且我确实得到了正确的结果,但问题是我认为我这样做是一种不方便的方法.这是代码:
for (int x = 1; x <= 4; x++) {
for (int y = 1; y <= x; y++) {
System.out.print("*");
}
System.out.println();
}
for (int x = 1; x <= 3; x++) {
for (int y = 3; y >= x; y--) {
System.out.print("*");
}
System.out.println();
}
Run Code Online (Sandbox Code Playgroud)