java--輸出一個菱形
阿新 • • 發佈:2017-12-20
main ++ pub package wid ace per args art
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(); } } }
結果展示:
java--輸出一個菱形