Saturday, November 1, 2014

Filled Under: , , , , ,

Diamond Pattern 2

Share

Code box
-------------------------

/* Program to print diamond pattern 2 */


class diam2
{
public static void main(String x[])
{

int i, j, k,n;

n=Integer.parseInt(x[0]);

System.out.println("---------------Diamond pattern-------------------\n");

for (i = 1; i <= n; i++)
{
for (j = 0; j < (n - i); j++)
System.out.print(" ");
for (j = 1; j <= i; j++)
System.out.print(i);

for (k = 1; k <i; k++)
System.out.print(i);

System.out.println();
}


for (i = n-1; i >= 1; i--)
{
for (j = 0; j < (n - i); j++)
System.out.print(" ");

for (j = 1; j <= i; j++)
System.out.print(i);

for (k = 1; k < i; k++)
System.out.print(i);

System.out.println(" ");

}
System.out.println(" ");
System.out.print("\n----------------------------------\n");

}

}


Note:Use Command line argument method to run the program.

0 comments:

Post a Comment