本节视频链接:https://www.bilibili.com/video/BV12J41137hu?p=44&vd_source=b5775c3a4ea16a5306db9c7c1c1486b5https://www.bilibili.com/video/BV12J41137hu?p=44&vd_source=b5775c3a4ea16a5306db9c7c1c1486b5
通过嵌套for循环可以实现打印三角形:
public class ForDemo06 {
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();
}
}
}