Follow us on twitter

Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.


    • CommentAuthorxTRiiXzZ-
    • CommentTimeNov 2nd 2009
     
    hi.

    i have a homework at collage.

    i want to make a program that show number from 0 to 100 in pyramid form.

    like this;

    (forget dots. i put them to make pyramid shape. just spacebar is not working)
    ....................1
    ..............2....3....4
    ....... 5....6....7....8....9
    .10...11..12...13..14..15...16
    .
    .
    .
    .
    .

    i know i am gonna use nested 'for' loops but i cant imagine the algorithm.

    can anyone help me pls?

    • CommentAuthorarshdeep79
    • CommentTimeApr 18th 2010
     

      LinkedList<Integer> list =new LinkedList<Integer>(); 

          for(int v = 1;v < 101; v++) { 
             list.add(v); 
          } 

          for(int i = 1;i < 20; i=i+2) { 
             for(int k = 0;k < 20-i;k++) { 
                System.out.print(" "); 
             } 
             for(int j = 0;j<i;j++) { 
                System.out.print(list.poll() + " "); 
             } 
             System.out.println(""); 
          }

     

    that's including the spaces


Add your comments