1 package com.hanqi; 2 3 public class Test10 { 4 5 public static void main(String[] args) { 6 //菱形 7 8 9 //上半部分 10 for (int m = 1; m <= 10; m++) 11 { 12 //输出空格 13 for (int n = 9; n >= m ;n--) 14 { 15 System.out.print(" "); 16 } 17 //输出* 左上 18 for (int n = 1; n <= m; n++) 19 { 20 System.out.print("*"); 21 } 22 23 //右上 24 for (int n = 1; n < m; n++) 25 { 26 System.out.print("*"); 27 } 28 29 System.out.println(); 30 } 31 32 //下半部分 33 for (int m = 1; m <= 9; m++) 34 { 35 //输出空格 36 for (int n = 1; n <= m ;n++) 37 { 38 System.out.print(" "); 39 } 40 //输出* 左下 41 for (int n = 9; n >= m; n--) 42 { 43 System.out.print("*"); 44 } 45 46 //右下 47 for (int n = 9; n > m; n--) 48 { 49 System.out.print("*"); 50 } 51 52 System.out.println(); 53 } 54 55 } 56 57 }
//输出三角形 //右上 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(); }