Translate

Saturday, 26 September 2015

Write a Java code to print following pattern

A
BC
DEF
GHIJ

Solution:
 
//PrintABCD.java
class PrintABCD
{
     public static void main(String abc[])
     {
        int alphabet=65;                          //ASCII value of A
        for(int i=1;i<5;i++)
        {           
            for(int j=1;j<=i;j++)
              {
                System.out.print((char)alphabet);
                alphabet++;
              }
          System.out.println();
         }
     }
}