AAAA
AAA
AA
A
A
AB
ABC
ABCD
Solution:
//PrintABCD.java
class PrintABCD
{
public static void main(String abc[])
{
printAAAA();
printABCD();
}
static void printABCD()
{
for(int i=1;i<5;i++)
{
for(int k=3;k>0;k--)
{
System.out.print(" ");
}
int alphabet=65; //ASCII value of A
for(int j=1;j<=i;j++)
{
System.out.print((char)alphabet);
alphabet++;
}
System.out.println();
}
}
static void printAAAA()
{
int alphabet=65; //ASCII value of A
for(int i=4;i>0;i--)
{
for(int k=4;k>i;k--)
{
System.out.print(" ");
}
for(int j=1;j<=i;j++)
{
System.out.print((char)alphabet);
}
System.out.println();
}
}
}
AAA
AA
A
A
AB
ABC
ABCD
Solution:
//PrintABCD.java
class PrintABCD
{
public static void main(String abc[])
{
printAAAA();
printABCD();
}
static void printABCD()
{
for(int i=1;i<5;i++)
{
for(int k=3;k>0;k--)
{
System.out.print(" ");
}
int alphabet=65; //ASCII value of A
for(int j=1;j<=i;j++)
{
System.out.print((char)alphabet);
alphabet++;
}
System.out.println();
}
}
static void printAAAA()
{
int alphabet=65; //ASCII value of A
for(int i=4;i>0;i--)
{
for(int k=4;k>i;k--)
{
System.out.print(" ");
}
for(int j=1;j<=i;j++)
{
System.out.print((char)alphabet);
}
System.out.println();
}
}
}