如何使用JAVA一层for循环打印出倒立三角形

如题所述

以下代码仅供参考

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++;
            }

        }
    }

温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-10-02
public class triangle {
public static void main(String[] args){
int a=6;
for(int i=5;i>=0;i--){
System.out.print("@");
if(i==0){
i=--a;
System.out.println();
}
}
}
}

相似回答