Tuesday, 24 January 2012

Print Stars Diamond Program in java

Print Stars Diamond Program in java

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

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

         boolean b1=true;
         boolean b2= true;
         for(int i=0;i<x;i++)
        {
             for(int j=0;j<y;j++)
            {
                 System.out.print(" ");
            }
            for(int k=0;k<z;k++)
            {
                System.out.print("*");
            }
            if(y==0) b1=false;
            if(z==x) b2=false;

            y=b1?y-1:y+1;
            z=b2?z+2:z-2;
            System.out.println();
        }
       
    }
}

1 comment: