zoukankan      html  css  js  c++  java
  • 打印正/倒三角

    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();
            }
    
        }
    }
    ==========    倒直角三角=======
    ****
    ***
    **
    *
    
    =========正直角三角============
    *
    **
    ***
    ****
    =========正等腰三角形============
        * 
       * * 
      * * * 
     * * * * 
    * * * * * 
    =========侄等腰三角形============
    * * * * * 
     * * * * 
      * * * 
       * * 
        * 
  • 相关阅读:
    2018.10.05模拟总结
    CentOS 7 分区方案
    Linux讲解之定时任务
    TrueCrypt与CryptSetup双系统全盘加密(图文)
    使用LUKS加密你的磁盘
    使用LUKS加密你的磁盘
    本文介绍使用windows系统自带的远程桌面mstsc连接Centos 7.x远程桌面的基本方法。
    Xrdp
    CentOS7开放端口以及常用的使用命令记录整理
    【Python成长之路】装逼的一行代码:快速共享文件
  • 原文地址:https://www.cnblogs.com/liunanjava/p/4786613.html
Copyright © 2011-2022 走看看