输出矩形、空心矩形、等腰三角形、菱形
public class text01{ public static void main(String[] args) { System.out.println("输出实心矩形"); int s=8; String a[][] = new String[s][s]; for(int i=0;i<s;i++) { for (int j=0;j<s;j++) { a[i][j] =" *"; System.out.print(a[i][j]); } System.out.println(); } System.out.print("\n"+"\n"+"\n"+"输出空心矩形"+"\n"); String b[][] = new String [s][s]; for(int i=0;i<s;i++) { for (int j=0;j<s;j++) { if (i>0&&i<s-1&&j>0&&j<s-1) { b[i][j] =(" "); } else { b[i][j] =(" *"); } System.out.print(b[i][j]); } System.out.println(); } System.out.print("\n"+"\n"+"\n"+"输出正三角形"); int c [][]=new int [7][13]; for (int i=0;i<7;i++) { c[i][6]=i+1; int n = i+1; int p=6; int q=6; while(n>1&&p<0){ c[i][--p] = i+1; } n=i+1; while(n>1&&p>0){ c[i][--p] = --n; } n=i+1; while(n>1&&q<12){ c[i][++q] = --n; } } for(int i=0;i<7;i++) { System.out.println(); for(int j=0;j<13;j++) { if (c[i][j]==0){ System.out.print(" "); } else{ System.out.print(c[i][j] +" "); } } } System.out.println(); System.out.print("\n"+"\n"+"\n"+"输出菱形"); for(int i=0;i<7;i++) { System.out.println(); for(int j=0;j<13;j++) { if(c[i][j]==0) { System.out.print(" "); }else { System.out.print(c[i][j]+ " "); } } } for(int i=6;i>=0;i--) { System.out.println(); for(int j=0;j<13;j++) { if(c[i][j]==0){ System.out.print(" "); }else{ System.out.print(c[i][j]+" "); } } } } }