Home >>Java Programs >Java program to print the following given pattern
Pattern:
A
B B
C C C
D D D D
E E E E E
In this example, we will see a Java program to print the above given pattern on the console.
In this program, we will need two loops, the first loop will be responsible for printing the line breaks whereas the second loop will be responsible for printing the alphabet.
Algorithm:
Program:
class Main
{
public static void main(String[] args)
{
int n = 4;
for(int i = 0 ; i <= n ; i++)
{
for(int j = 0 ; j <= i ; j++)
{
System.out.print(" "+(char)(65 + i));
}
System.out.println("");
}
}
}