java源代码:
package studying; /* * Print Diamond */ public class PrintDiamond { public static void main(String[] args) { //Upper part for(int m = 1; m <= 10; m++) { //Output Spaces for(int n = 9; n >= m; n--) { System.out.print(" "); } //Output * Upper Left for(int n = 1; n <= m; n++) { System.out.print("*"); } //Output * Upper Right for(int n = 1; n < m; n++) { System.out.print("*"); } System.out.println(); } //Second half for(int m = 1; m <= 9; m++) { //output spaces for(int n = 1; n<=m; n++) { System.out.print(" "); } //Output * Lower left for(int n = 9; n >= m; n--) { System.out.print("*"); } //Output * Lower right for(int n = 9; n > m; n--) { System.out.print("*"); } System.out.println(); } } }
结果展示: