Pattern 2


We can print the following Pattern 
1)
* * * * *           //print *
 * * * * 
  * * * 
   * * 
    * 

2)
5 4 3 2 1    //Print j
 4 3 2 1 
  3 2 1 
   2 1 
    1 

3)
5 5 5 5 5  //Print i
 4 4 4 4 
  3 3 3 
   2 2 
    1 



package demo;

import java.util.Scanner;

public class Pattern2 {
 public static void main(String[] args) {
  Scanner sc = new Scanner(System.in);
  
  System.out.println("Enter the number");
  int n=sc.nextInt();
  for(int i=n;i>=1;i--) {
   for(int k=n-1;k>=i;k--) {
    System.out.print(" ");
   }
   for(int j=i;j>=1;j--) {
    System.out.print("* ");
    //System.out.print(j+ " ");
    //System.out.print(i+ " ");
   }
   System.out.println();
  }
 }
}


O/P:-
Enter the number
5
5 4 3 2 1 
 4 3 2 1 
  3 2 1 
   2 1 
    1