package demo1; public class Demo { public static void main(String[] args) { int a=4; for(int i=1;i<=a;i++) { for(int k=1;k<=a-i;k++) { System.out.print(" "); } for(int j=1;j<=(i-1)*2+1;j++) { System.out.print("*"); } System.out.println(); } } }
*
***
*****
*******
package demo1; public class Demo { public static void main(String[] args) { int a=4; for(int i=1;i<=a;i++) { for(int k=1;k<=a-i;k++) { System.out.print(" "); } for(int j=1;j<=(i-1)*2+1;j++) { if(i==1||i==a) { System.out.print("*"); } else { if( j==1||j==(i-1)*2+1) { System.out.print("*"); } else { System.out.print(" "); } } } System.out.println(); } } }
*
* *
* *
*******
原文:http://www.cnblogs.com/zznlovexw/p/5215303.html