Java Program:

- To print sideway reverse triangle 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 columns : ");

    int columns,trows,k;
    columns=userInput.nextInt();
    trows=2*columns-1;
    k=trows;
    for(int i=trows; i>=1; i--) {
      for(int j=1; j<=trows; j++) {
        if(j<k)System.out.print("  ");
        else System.out.print("* ");
      }
      if(i<=columns)k++;
      else k--;
      System.out.print("\n");
    }

  }
}

Output:

Enter number of columns: 4

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

Main Logic :

trows=2*columns-1;   // trows : total rows to print
k=trows;  // Used to trigger decreasing order of *

for(int i=trows; i>=1; i--) {
   for(int j=1; j<=trows; j++) {
    if(j<k)System.out.print("  ");
    else System.out.print("* ");
  }
  //check for position change at which triangle * value to decrease
  if(i<=columns)k++;
  else k--;
  System.out.print("\n");
}

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

Concept

Coming Soon !

Quick
Tutorial

Quote

A good decision is based on knowledge and not on numbers.