12、打印三角形及Debug

三角形

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();
        }
    }
    }

输出

     *
    ***
   *****
  *******
 *********
  1. 实质上还是一行一行输出
  2. 注意第二个for和第三个for的打印*个数不一样

学习使用Debug

猜你喜欢

转载自blog.csdn.net/weixin_45809838/article/details/115225438