本帖最后由 风悠悠 于 2013-9-30 16:40 编辑
- public static void main(String[] args) {
- int MaxNum=5;
- int NowNum=MaxNum;
- int printLen=0;
- boolean sign=true;
- int high=MaxNum*2-1;
- while(high>0){
- printLen=(MaxNum-NowNum)*2+1;
- print(NowNum,printLen);
- high--;
- if(NowNum==1)
- sign=false;
- if(sign)
- NowNum--;
- if(!sign)
- NowNum++;
- }
- }
- public static void print(int NowNum,int printLen){
- int count=NowNum;
- while(count-1>0){
- System.out.print(" ");
- count--;
- }
- while(printLen>0){
- if(printLen==1)
- System.out.println(NowNum);
- else
- System.out.print(NowNum);
- printLen--;
- }
- }
复制代码 打印结果
5
444
33333
2222222
111111111
2222222
33333
444
5
|