以下代码仅供参考
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++;
}
}
}