alpe gulay's program to create a diamond using asterisk...

alpe gulay 0 Tallied Votes 182 Views Share

.,'this program will simply creates a diamond using asterisk.,'
just try out this code i am sure you will be interested.!..
email me about your comment in this simple program!..help me if you know the easiest way to construct this kind of program..'

import javax.swing.*;
public class alpe_diamond_program
{
    public static void main(String []args)
    {
    getri();    
    }
    
    public static void getri()
    {
            int x,y,z;
        int a=1;
        String out="\n";
        
        int i=Integer.parseInt(JOptionPane.showInputDialog("Enter the size!"));
        if((i%2)!=0)
        {
        
        
        int in=(i/2)+(i%2);
        int bb=in-1;
        int b=bb+(bb-1);
        
        
        for(x=in;x>0;x--)
        {
            
            for(y=x;y>1;y--)
                out+=" ";
            
                for(z=0;z<a;z++)
                    out+="*";
                    a+=2;
                    out+="\n";
        }
        
            
        for(x=0;x<in-1;x++)
        {
            
            for(y=x;y>=0;y--)
                out+=" ";
            
                for(z=0;z<b;z++)
                    out+="*";
                    b-=2;
                    out+="\n";
        }
                
        
        System.out.print(out);
        getri();}
        else
        {
                System.out.print("I can't process!");
                getri();
        }
    }
}
//email me about your comment in this code!!!jalpex91@gmail.com