Thursday, October 27, 2011

Printing a dual pyramid pattern of '*' #4

//This java program accepts a number of user
//which tells the program that how many lines
//of the pattern will be printed.
/*Sample Input :7
Sample Output :

            *
          *A*
        *A*A*
      *A*A*A*
    *A*A*A*A*
  *A*A*A*A*A*
*A*A*A*A*A*A*   */



import java.util.*;
class pattern
{
public static void main()
{
    System.out.print("Enter the number of lines you want: ");
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int i,j,k=1;
    for(i=1;i<=n;i++,k+=2)
    {
        for(j=n;j>i;j--)
        {
            System.out.print(" ");
        }
        for(j=1;j<=k;j++)
        {
            if(j%2==0)
            {
                System.out.print("A");
            }
            else
            {
                System.out.print("*");
            }
        }
        System.out.println();
    }
}
}

//Author: Mayank Rajoria

No comments:

Post a Comment