Inverted Alphabet Triangle

This program prints an inverted alphabet triangle.

Problem Statement

Write a Java program that prints an inverted alphabet triangle with 5 rows.

Source Code

1 public class InvertedAlphabetTriangle {
2 public static void main(String[] args) {
3 int n = 5;
4 for(int i=n; i>=1; i--) {
5 char ch = 'A';
6 for(int j=1; j<=i; j++) {
7 System.out.print(ch + " ");
8 ch++;
9 }
10 System.out.println();
11 }
12 }
13 }

Program Output

A B C D E 
A B C D 
A B C 
A B 
A 

Explanation

The outer loop starts at 5 and decreases each iteration while the inner loop prints alphabets starting from 'A' up to the current row count, so each row prints fewer alphabets, forming an inverted alphabet triangle.

Quick Links to Explore