Friday, August 10, 2012

Pyramid Program


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

How ChatGPT can Benefit Coding: Your Guide to Leveraging an AI Language Model

 Introduction: Hello, coders! Welcome to this blog post on how ChatGPT, an AI language model, can benefit your coding skills and projects. A...