Sunday, October 16, 2011

Printing a dual pyramid pattern of '*' #2

//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 :6
Sample Output :
  *****
* ****
** ***
*** **
**** *
*****  
*/


import java.util.*;
class pattern
{
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;i++)
    {
        for(j=1;j<=n;j++)
        {
            if(i==j)
            {
                System.out.print(" ");
            }
            else
            {
                System.out.print("*");
            }
        }
        System.out.println();
    }
}
}
//Author : Mayank Rajoria

No comments:

Post a Comment