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(); } } }
*
* *
* *
*******
时间: 2024-11-10 07:24:24