How to print door pattern in java

The printing of door pattern need more attention of yours as in this pattern we have to print the first line alone to make it perfect .

Code for printing door pattern:-

import java.util.Scanner;

 

public class doorpattern1 {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int n;
n=s.nextInt();
int h=2*n-1;
for(int i=n;i>=1;i–)
{
  if(i!=n)
{
   for(int j=1;j<=i;j++)
  System.out.print(“* “);
  for(int m=1;m<=h-2*i;m++)
  System.out.print(” “);
  for(int j=1;j<=i;j++)
  System.out.print(“* “);
}
else
   {
     for(int x=1;x<=n;x++)                                             / / if i=n then it will print a line of stars at the top.
     System.out.print(“* “);
     for(int x=n-1;x>=1;x–)
     System.out.print(“* “);
  }
System.out.println()

  }
    }
   }

2 thoughts on “How to print door pattern in java”

Leave a Reply