Java Program:

- To print full triangle pattern using number

Example:

User Input: 3

Output:

    1
  1 2 1
1 2 3 2 1
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,k;
    rows=userInput.nextInt();
    for(int i=rows; i>=1; i--) {
      k=1;
      for(int j=1; j<=(2*rows-i); j++) {
        if(j<i)System.out.print("  ");
        else {
          if(j<rows)System.out.print(k++ +" ");
          else System.out.print(k-- +" ");
        }
      }
      System.out.print("\n");
    }

  }
}

Output:

Enter number of rows: 4

      1
    1 2 1
  1 2 3 2 1
1 2 3 4 3 2 1
Program
pattern

Main Logic :

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

Coming Soon !

Quick
Tutorial

Quote

The best preparation for good work tomorrow is to do good work today.