Saturday, 1 September 2012

Pyramid Program 1


Output
----------
    *
   * *
  * * *
 * * * *
* * * * *

Pyramid Program 1
Source code
-------------
package com.swain.cell;

public class Piramid {

       public static void main(String args[]){
              int p=1;
              for(int i=1;i<=5;i++){
                     for(int j=i;j<5;j++){
                           System.out.print(" ");
                     }
                     for(int k=1;k<=p;k++){
                           if(k%2==0){
                                  System.out.print(" ");

                           }else
                           System.out.print("*");

                     }
                     System.out.println();
                     p+=2;
              }
       }
}

No comments:

Post a Comment