Wednesday, 14 October 2020

Print the following pattern

 A A A A A 1
B B B B 1 2
C C C 1 2 3
D D 1 2 3 4
E 1 2 3 4 5


import java.util.*;
public class pattern 
{
 public static void main(String args[])
 {
 int i,j,n;
 Scanner sc = new Scanner(System.in);
     System.out.println("Enter the no of lines");
 n=sc.nextInt();
     for(i=1;i<=n;i++)
     {
         for(j=i;j<=n;j++)
         {
             System.out.print((char)(i+64));
            }
         
            for (int y = 1; y <= i; y++)
            {
                System.out.print(y);
            }
                      
         System.out.println("");
     }
 }
}

No comments:

Post a Comment