Pattern 4


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

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

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

4)
A A A A A     //(char)(i+64)
B B B B 
C C C 
D D 
E 

5)
E D C B A      //(char)(j+64)
E D C B 
E D C 
E D 
E 

package demo;

import java.util.Scanner;

public class Pattern4 {
 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=1;i<=n;i++) {
   for(int j=5;j>=i;j-- ) {
    //System.out.print("* ");
    //System.out.print(i+ "5 ");
    //System.out.print(j+ " ");
    //System.out.print((char)(i+64)+ " ");
    System.out.print((char)(j+64)+ " ");
   }
   System.out.println();
    
   }
 } 
 }
O/P:-
Enter the number
5
E D C B A 
E D C B 
E D C 
E D 
E