代码块:
方法一:(直接输出)
package Test; public class Test { public static void main(String[] args) { System.out.println(" *"); System.out.println(" ***"); System.out.println(" *****"); System.out.println(" *******"); System.out.println("*********"); System.out.println(" *******"); System.out.println(" *****"); System.out.println(" ***"); System.out.println(" *"); } }
方法二:(利用循环结构)
package Test; public class Test { public static void main(String[] args) { int i, j, k; for(i=0; i<5; i++) { for(j=4-i; j>0; j--) System.out.print(" "); for(k=0; k<2*i+1; k++) System.out.print("*"); System.out.println(); } for(i=0; i<4; i++) { for(j=0; j<i+1; j++) System.out.print(" "); for(k=7-2*i; k>0; k--) System.out.print("*"); System.out.println(); } } }