图形代码
package com.hanqi; public class Test10 { public static void main(String[] args) { //输出三角形 for(int m = 1; m <= 10; m++) { for (int n = 1; n <= m; n++) { System.out.print("*"); } System.out.println(); } // for(int m = 1; m <= 9; m++) // { // for (int n = 9; n >= m; n--) // { // System.out.print("*"); // } // // System.out.println(); // } 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(); } // 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(); // } for (int m = 9; 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(); } System.out.println(); 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(); } } }