public class IsoscelesTriangle { /** * 等腰三角形 */ public void print1(){//形如 ▲向上的 for(int i=1;i<=5;i++){ for(int k=1;k<=5-i;k++) System.out.print(" "); for(int j=1;j<=2*i-1;j++) System.out.print("*"); System.out.print("\n"); } } public void print2(){//形如:倒▲ 向下的 for(int i=1;i<=5;i++){ for(int j=1;j<=i-1;j++) System.out.print(" "); for(int k=1;k<=11-(2*i);k++) System.out.print("*"); System.out.print("\n"); } } public static void main(String[] args) { IsoscelesTriangle app = new IsoscelesTriangle(); System.out.println("---------------------------"); app.print1(); System.out.println("---------------------------"); app.print2(); System.out.println("---------------------------"); } }