package com.print.xingzhuang; public class Print_SanJiaoXing { public static void main(String[] args) { System.out.println("------------第一行5个------------"); for (int i = 0; i < 5; i++) { for (int j = 5; j > i; j--) { System.out.print("*");//这里不能回车 } System.out.println(); } System.out.println("--------------第一行1个-------------"); for (int i = 0; i < 5; i++) { for (int j = 0; j <= i; j++) { System.out.print("*"); } System.out.println(); } System.out.println("--------------等腰--------------"); for (int i = 0; i < 5; i++) { for (int j = 0; j < 5-i; j++) { System.out.print(" "); } for (int k = 0; k < 2*i+1; k++) { System.out.print("*"); } System.out.println(""); } } } 结果:
------------第一行5个------------ ***** **** *** ** * --------------第一行1个------------- * ** *** **** ***** --------------等腰-------------- * *** ***** ******* *********
打印三角形
时间: 2024-10-15 09:14:23