Java program for printing a pattern of java

import java.io.*;

class pattern
{
public static void main(String args[]) throws Exception

{
int n,i,j,s,t=-1;


BufferedReader br= new BufferedReader(new InputStreamReader(System.in));


System.out.println("ENTER a number");
n=Integer.parseInt(br.readLine());






for(i=n;i>=1;i--)
{

for(j=i;j>=1;j--)
System.out.print("*");


for(s=1;s<=t;s++)
System.out.print(" ");
t+=2;


j=i;

if(j==n)
j=j-1;

for(;j>=1;j--)
System.out.print("*");

System.out.println();

}


t=t-2;

for(i=2;i<=n;i++)
{

for(j=1;j<=i;j++)
System.out.print("*");

t-=2;

for(s=t;s>=1;s--)
System.out.print(" ");



j=i;

if(j==n)
j=j-1;

for(;j>=1;j--)
System.out.print("*");

System.out.println();

}




}
}

ENTER a number
*********
****  ****
***      ***
**         **
*             *
**         **
***      ***
****  ****
*********
Post a Comment