输出棱形图案
2019獨角獸企業重金招聘Python工程師標準>>>
/*** n=1, n=2 n=3* * * ** *** **** * ****** **** ** @param n*/public static void print(int n) {int sb = 2*n - 1;int i = 1;//輸出上三角while(i < n) {int m = 2*i - 1;int b = (sb-m)/2;while(b > 0) {System.out.print(" ");b--;}while(m > 0) {System.out.print("*");m--;}i++;System.out.println();}//輸出下三角while(n > 0) {int m = 2*n - 1;int b = (sb-m)/2;while(b > 0) {System.out.print(" ");b--;}while(m > 0) {System.out.print("*");m--;}n--;System.out.println();}}print(5)
? ? *
? ?***
? *****
?*******
*********
?*******
? *****
? ?***
? ? *
轉載于:https://my.oschina.net/u/2342541/blog/1802086
總結
- 上一篇: 一文带你秒懂 字节序(byte orde
- 下一篇: 概率分布 ---- 二项分布