//输出三角形 //左下 for(int m = 1; m <= 10; m++) { for (int n = 1; n <= m; n++) { System.out.print("*"); } System.out.println(); } //左上(1) for(int m = 1; m <= 10; m++) { for (int n = 10; n >= m; n--) { System.out.print("*"); } System.out.println(); } //左上(2) for(int m = 9; m >= 1; m--) { for (int n = 1; n <= m; n++) { System.out.print("*"); } System.out.println(); } //右下 for (int m = 1; m <= 10; m++) { //输出空格 for (int n = 9; n >= m ;n--) { System.out.print(" "); } //输出* for (int n = 1; n <= m; n++) { System.out.print("*"); } System.out.println(); } //右上(1) for (int m = 1; m <= 9; m++) { //输出空格 for (int n = 1; n <= m ;n++) { System.out.print(" "); } //输出* for (int n = 9; n >= m; n--) { System.out.print("*"); } System.out.println(); } //右上(2) for (int m = 10; m >= 1; m--) { //输出空格 for (int n = 9; n >= m ;n--) { System.out.print(" "); } //输出* for (int n = 1; n <= m; n++) { System.out.print("*"); } System.out.println(); } // // // // // //菱形(方法一) // //上半部分 for (int m = 1; m <= 10; m++) { //输出空格 for (int n = 9; n >= m ;n--) { System.out.print(" "); } //输出* 左上 for (int n = 1; n <= m; n++) { System.out.print("*"); } //右上 for (int n = 1; n < m; n++) { System.out.print("*"); } System.out.println(); } //下半部分 for (int m = 1; m <= 9; m++) { //输出空格 for (int n = 1; n <= m ;n++) { System.out.print(" "); } //输出* 左下 for (int n = 9; n >= m; n--) { System.out.print("*"); } //右下 for (int n = 9; n > m; n--) { System.out.print("*"); } System.out.println(); } //菱形(方法二) int x=0; int x1=0; for(int i=0;i<5;i++){ for(int j=0;j<10;j++){ x=5+i; x1=5-i; if(j>=x1&&j<=x){System.out.print ("*");} else{System.out.print(" ");} } System.out.println(); } int x3=0; int x4=0; for(int i=1;i<5;i++){ for(int j=0;j<10;j++){ x3=i; x4=10-i; if(j>x3&&j<x4){System.out.print ("*");} else{System.out.print(" ");} } System.out.println(); }