Sunday, January 1, 2012

Program to demonstrate usage of allocating memory dynamically to second dimension of array, by displaying following pattern in Java


             X
          XXX
        XXXXX
      XXXXXXX
   XXXXXXXXX
XXXXXXXXXXX
   XXXXXXXXX
     XXXXXXX
       XXXXX
        XXX
           X
Example

import java.util.*;
class A404307
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int a,j,k,i;
System.out.println("Enter The Value Of Number of Pattern ::");
a=sc.nextInt();
for(i=1;i<=a;i++)
{
for(j=a-i;j>0;j--)
{
System.out.print(" ");
}
for(k=1;k<=i;k++)
{
System.out.print(" *");
}
System.out.println();
}
for(i=a;i>=1;i--)
{
for(j=a-i;j>0;j--)
{
System.out.print(" ");
}
for(k=1;k<=i;k++)
{
System.out.print(" *");
}
System.out.println();
}
}
}

No comments:

Post a Comment