Sunday, October 16, 2011

Printing a dual pyramid pattern of '*' #3

//This Java program accepts a number from the
//user and prints a dual pyramid using '*' depending
//on the number entered by the user
/* Sample Input :8
Sample Output :
* ******
** *****
*** ****
**** ***
***** **
****** *    */

import java.util.*;
class pattern7
{
public static void main()
{
    Scanner sc=new Scanner(System.in);
    System.out.print("Enter the size of pattern you want : ");
    int n=sc.nextInt();
    int i,j;
    for(i=1;i<=(n-2);i++)
    {
        for(j=1;j<=(n);j++)
        {
            if(j==(i+1))
            {
                System.out.print(" ");
            }
            else
            {
                System.out.print("*");
            }
        }
        System.out.println();
    }
}
}
//Author : Mayank Rajoria

No comments:

Post a Comment