三角形
package com.wzt.www.struct;
/**
* @author WZT
* @create 2021-03-25 22:13
*/
public class TestDemo {
//打印三角形 5行
public static void main(String[] args) {
for (int i = 1; i <= 5; i++) {
for (int j = 5; j >= i; j--) {
System.out.print(" ");
}
for (int j = 1; j <= i; j++) {
System.out.print("*");
}
for (int j = 1; j < i; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
输出
*
***
*****
*******
*********
- 实质上还是一行一行输出
- 注意第二个for和第三个for的打印*个数不一样