Print reverse pyramid of numbers

前端 未结 5 801
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-29 17:08

I am able to print pyramid like this :

   1
  123
 12345
1234567

Code i used to print the pyramid of numbers like a

5条回答
  •  终归单人心
    2021-01-29 17:22

    int w = 7;
            System.out.println("Here is your pattern....!!!");
    
            for (int i = 1; i <= 5; i++)
            {
                //Printing i spaces at the beginning of each row
    
                for (int j = 1; j < i; j++)
                {
                    System.out.print(" ");
                }
    
                //Printing i to rows value at the end of each row
    
                for (int j = 1; j <=w; j++)
                {
                    System.out.print(j+" ");
                }
                w = w - 2;
    
                System.out.println();
            }
    

提交回复
热议问题