打印三角形
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个------------- * ** *** **** ***** --------------等腰--------------
* *** ***** ******* *********
逃避不一定躲得过,面对不一定最难过