Pattern 7


We can print the following Pattern 
1) 
    A      //print (char)(j+64)  and i
   2 2 
  A B C 
 4 4 4 4 

2) 
    A       //print (char)(j+64)  and j
   1 2 
  A B C 
 1 2 3 4 

3) 
    A         //print (char)(i+64)  and i
   2 2 
  C C C 
 4 4 4 4 

4)
    A           //print (char)(i+64)  and j       
   1 2 
  C C C 
 1 2 3 4


package demo;

import java.util.Scanner;

public class Pattern8 {
 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=i;k--) {
    System.out.print(" ");
   }
   for(int j=1;j<=i;j++) {
    //System.out.print("* ");
    if(i%2 != 0) {
     System.out.print((char)(j+64)+ " ");
    }
    else
    {
     System.out.print(i+ " ");
    }
   }
   System.out.println();
  }
 }
}
O/P:-
Enter the number
5
    A 
   2 2 
  A B C 
 4 4 4 4