Pattern program 2


Input 1 output *
Input 2 output
 *
**

Input 3 output
  *
 * *
* * *

Input 4 output
   *
  *  *
 *    *
* * * *

	import java.io.*;
	class pattern2
	{
		public static void main(String args[])
		{
			Console con = System.console();
			int n = Integer.parseInt(con.readLine());
			for(int i=1;i<=n;i++)
			{
				if(i==n)
				{
					for(int j=1;j<=n+i-1;j++)
						System.out.print(" *");
					}
				else
				{
					for(int j=1;j<=n-i;j++)
						System.out.print("  ");
					for(int j=n-i+1;j<=n+i-1;j++)
					{
						if(j==n-i+1||j==n+i-1)
							System.out.print(" *");
						else
							System.out.print("  ");
					}
					System.out.println();
				}
			}
		}
	}

Comments