public void printTriangle(int height) {
int space = height - 1;
int star = 1;
for (int i = 0; i < height; i++) {
for (int j = 0; j < space; j++) {
System.out.print(" ");
}
for (int j = 0; j < star; j++) {
System.out.print("*");
}
space--;
star += 2;
System.out.println();
}
}
結果printTriangle(5);