Java classic applet: 8. Print triangles

topic

Use the program to output the following graphics:

*
* * *
* * * * *
* * * * * * *
* * * * *
* * *
*

code

package org.hbin.example;

/**
 * 
 * @author hbin
 * @date 2020/11/16
 */
public class PrintTriangleTest {
    
    

    public static void main(String[] args) {
    
    
        printTriangle();
    }

    private static void printTriangle() {
    
    
        for (int i = 0; i < 7; i++) {
    
    
            for (int j = 0; j < i * 2 + 1 && j < 13 - i * 2; j++) {
    
    
                System.out.print("* ");
            }
            System.out.println();
        }
    }
}

Guess you like

Origin blog.csdn.net/binbinxyz/article/details/109731243