1 //1.菱形 2 public static void Lingxing(int size){ 3 if(size % 2 == 0){ 4 size++;//计算菱形大小 5 } 6 //输出菱形上半部 7 for (int i = 0; i < size/2 + 1; i++) { 8 for (int j = size/2 + 1; j > i + 1; j--) { 9 System.out.print(" ");//输出左上角位置的空白 10 } 11 for (int j = 0; j < 2*i + 1; j++) { 12 System.out.print("*");//输出菱形上半部 13 } 14 System.out.println();// 换行 15 } 16 // 输出菱形下半部 17 for (int i = size/2 + 1; i < size; i++) { 18 for (int j = 0; j < i - size/2; j++) { 19 System.out.print(" ");// 输出菱形左下角空白 20 } 21 for (int j = 0; j < 2*size-1 - 2*i ; j++) { 22 System.out.print("*");// 输出菱形下半部 23 } 24 System.out.println(); 25 } 26 } 27 28 // 2.九九乘法表 29 public static void MultiplicationTable(){ 30 for (int i = 1; i <= 9; i++) { 31 for (int j = 1; j <= i; j++) { 32 System.out.print(j+"x"+i+"="+i*j+"\t");// \t 跳到下一个TAB位置 33 } 34 System.out.println(""); 35 } 36 } 37 38 //3. 打印三角形 39 public static void Triangle(int n){ 40 for (int i = 0; i <= n; i++) { 41 for (int j = n; j >= i; j--) { 42 System.out.print(" ");//建立1号图形 43 } 44 for (int j = 1; j <= i; j++) { 45 System.out.print("*");//建立2号图形 46 } 47 for (int j = 1; j < i; j++) { 48 System.out.print("*");//建立3号图形 49 } 50 System.out.println(""); 51 } 52 } 53 54 //4.打印倒立的三角形 55 public static void InvertedTriangle (int i) { 56 //打印倒立的三角形 57 for (int m = 1; m <= i; m++) { 58 //打印空格 59 for (int n = 0; n <= m; n++) { 60 System.out.print(" "); 61 } 62 //打印* 63 for (int x = 1; x <= 2*(i - m) + 1; x++) { 64 System.out.print("*"); 65 } 66 System.out.println(); 67 } 68 } 69 70 //5.打印平行四边形 71 public static void Parallelogram (int n) { 72 //外层循环 每次打出一个* 73 for (int i = 1; i <=n; i++) { 74 //填充空格 75 for (int j = 1; j <= n - i; j++) { 76 System.out.print(" "); 77 } 78 //内层循环 每次打印一个* 79 for (int k = 1; k <=n; k++) { 80 System.out.print("*"); 81 } 82 System.out.println(); 83 } 84 } 85 86 //6.打印平行四边形 87 public static void Rectangle (int n) { 88 //外层循环 每次打出一个* 89 for (int i = 1; i <=n; i++) { 90 //外层循环 每次输出一行* 91 System.out.print("*"); 92 93 //内层循环 每次打印一个* 94 for (int k = 1; k <=n; k++) { 95 System.out.print("*"); 96 } 97 System.out.println(); 98 } 99 }