Java Program:

- To print alphabet A pattern using *

Example:

User Input: 3

Output:

    *
  * * *
*       *
import java.util.Scanner;

public class Pattern {

  public static void main(String[] args) {
    Scanner userInput = new Scanner(System.in);
    System.out.print("Enter number of rows : ");

    int rows;
    rows=userInput.nextInt();
    for(int i=rows; i>=1; i--) {
      for(int j=1; j<=(2*rows-i); j++) {
        if(j==i||j==(2*rows-i)||(j>i && i==rows/2+rows%2)) {
          System.out.print("* ");
        }
        else {
          System.out.print("  ");
        }
      }
      System.out.print("\n");
    }

  }
}

Output:

Enter number of rows: 5

        *
      *   *
    * * * * *
  *           *
*               *
Program
pattern

Main Logic :

for(int i=rows; i>=1; i--) {
  for(int j=1; j<=(2*rows-i); j++) {
    if(j==i||j==(2*rows-i)||(j>i && i==rows/2+rows%2)) {
      System.out.print("* ");
    }
    else {
      System.out.print("  ");
    }
  }
  System.out.print("\n");
}

You can print any thing in this pattern, just replace your value with *

Concept

Coming Soon !

Quick
Tutorial

Quote

Sometimes it’s the smallest decisions that can change your life forever.