打印正/倒三角

package com.demo1;

/**
 * 打印正/倒三角
 * 
 * @author denny 正三角改变 初始化值 侄三角改变 循环条件
 */
public class Demo6 {

    public static void main(String[] args) {

        print(5);    // 倒直角三角
        printzhen(4);// 正直角三角
        printZhenDenng(5);// 正等腰三角形
        printDaoDenng(5); // 倒等腰三角形
    }

    // 倒直角三角
    public static void print(int row) {
        System.out.println("==========    倒直角三角=======");
        for (int x = 0; x < row; x++) {
            for (int y = x + 1; y < row; y++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }

    // 正直角三角
    public static void printzhen(int row) {
        System.out.println("=========正直角三角============");
        for (int x = 0; x < row; x++) {
            for (int y = 0; y <= x; y++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }

    // 正等腰三角形
    public static void printZhenDenng(int row) {
        System.out.println("=========正等腰三角形============");
        for (int x = 0; x < row; x++) { // 控制显示多少行

            // 控制显示多少空格
            for (int y = x + 1; y < row; y++) {
                System.out.print(" ");
            }

            // 控制显示多少个×号
            for (int z = 0; z <= x; z++) {
                System.out.print("* ");
            }
            System.out.println();
        }

    }

    // 倒等腰三角形
    public static void printDaoDenng(int row) {
        System.out.println("=========侄等腰三角形============");
        for (int x = 0; x < row; x++) { // 控制显示多少行

            // 控制显示多少空格
            for (int y = 0; y < x; y++) {
                System.out.print(" ");
            }

            // 控制显示多少个*号
            for (int z = x; z < row; z++) {
                System.out.print("* ");
            }
            System.out.println();
        }

    }
}
==========    倒直角三角=======
****
***
**
*

=========正直角三角============
*
**
***
****
=========正等腰三角形============
    * 
   * * 
  * * * 
 * * * * 
* * * * * 
=========侄等腰三角形============
* * * * * 
 * * * * 
  * * * 
   * * 
    * 
原文地址:https://www.cnblogs.com/liunanjava/p/4786613.html