Pattern program in java – AbcDEFghijKLMNO

Write a program in java to print the following pattern

A
b c
D E F
g h i j
K L M N O

class Pattern
{
    public static void main(String args[])
    {
        char c = 'A';
        for(int i=1; i<=5; i++)
        {
            if(i%2==0)
                c = Character.toLowerCase(c);
            else
                c = Character.toUpperCase(c);
                
            for(int j=1; j<=i; j++)
            {
                System.out.print(c + " ");
                c++;
            }
            System.out.println();
        }
    }
}

Leave a Comment

Your email address will not be published. Required fields are marked *