练习:菱形




1
//上半部分 2 for (int m = 1; m <= 10; m++) 3 { 4 //输出空格 5 for (int n = 9; n >= m ;n--) 6 { 7 System.out.print(" "); 8 } 9 //输出* 左上 10 for (int n = 1; n <= m; n++) 11 { 12 System.out.print("*"); 13 } 14 15 //右上 16 for (int n = 1; n < m; n++) 17 { 18 System.out.print("*"); 19 } 20 21 System.out.println(); 22 } 23 24 //下半部分 25 for (int m = 1; m <= 9; m++) 26 { 27 //输出空格 28 for (int n = 1; n <= m ;n++) 29 { 30 System.out.print(" "); 31 } 32 //输出* 左下 33 for (int n = 9; n >= m; n--) 34 { 35 System.out.print("*"); 36 } 37 38 //右下 39 for (int n = 9; n > m; n--) 40 { 41 System.out.print("*"); 42 } 43 44 System.out.println(); 45 }

输出结果:

posted @ 2016-02-26 20:44  庚xiao午  阅读(194)  评论(0编辑  收藏  举报