Posted by: Sourav | July 17, 2014

Diamond Pattern in Java


class triangle{

public static void main(String args[])
{
int i,j;

for(i=9;i>=0;i=i-2)
{

for( j=(i/2);j>0;j–)
{
System.out.print(” “);
}
for(j=(10-i);j>0;j–)
{
System.out.print(“*”);
}
for( j=(i/2);j>0;j–)
{
System.out.print(” “);
}
System.out.println();
}
for(i=3;i<10;i=i+2)
{
for(j=(i/2);j>=1;j–)
{
System.out.print(” “);
}
for(j=(10-i);j>=1;j=j-1)
{
System.out.print(“*”);

}
for(j=(i/2);j>=1;j–)
{
System.out.print(” “);
}
System.out.println();
}

}

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: