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(); } }}
========== 倒直角三角=======**********=========正直角三角============**********=========正等腰三角形============ * * * * * * * * * * * * * * * =========侄等腰三角形============* * * * * * * * * * * * * * *
新聞熱點
疑難解答