
如何使用JAVA一层for循环打印出倒立三角形
2个回答
展开全部
以下代码仅供参考
public static void main(String[] args) {
int maxRow = 5;
for (int currentIndex = 0, currentRow = 0; currentRow < maxRow;) {
if (currentIndex % maxRow < currentRow) {
System.out.print(" ");
} else {
System.out.print("* ");
}
currentIndex++;
if (currentIndex % maxRow == 0) {
System.out.println("\r");
currentRow++;
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询