Tuesday, 24 January 2012

Print Stars Pyramid Program in java

Print Stars Pyramid Program in java


The following program shows how to write a program to print stars pyramid in java
print stars pyramid program in java,write a java program to print stars,write a java program to print pyramid,write a program to print stars pyramid,printing stars program.

class Pyramid
{
    public static void main(String[] args)
    {
         int x=11;
         int y=x/2; // spaces
         int z=1; // *`s

         for(int i=0;i<5;i++)
        {
             for(int j=0;j<y;j++)
            {
                 System.out.print(" ");
            }
            for(int k=0;k<z;k++)
            {
                System.out.print("*");
            }

            y=y-1;
            z=z+2;
            System.out.println();  //new line
        }
       
    }
}



8 comments:

  1. Replies
    1. this is smart work no need to write more program for this

      Delete
    2. no u r ri8 swati its need more programme to make self smart...

      Delete
  2. can u give a little explaination about it aswell please ..?

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. // Simplest Way //

    public class Star6 {
    public static void main(String[] args)throws IOException {

    int x,i,j,k;

    InputStreamReader isr=new InputStreamReader(System.in);
    BufferedReader br=new BufferedReader(isr);

    System.out.println("Enter Rows"); x=Integer.parseInt(br.readLine());

    for(i=1;i<=x;i++){
    for(k=x;k>=i;k--){
    System.out.print(" ");
    }
    for(j=0;j<(i*2)-1;j++){
    System.out.print("*");
    }System.out.println();
    }
    }
    }

    ReplyDelete
  5. hi guys yes we can write more program as a programmer can think differently and can apply own logic
    thanks for reply

    ReplyDelete
  6. the simplest way


    public class For {

    public static void main(String[] args) {
    for(int i=1;i<=9;i++)
    {
    System.out.println();
    for(int k=9;k>=i;k--)
    System.out.print(" ");
    for(int j=1;j<=i;j++)
    System.out.print(" *");
    }}

    ReplyDelete