Reverse Alphabet Decreasing Triangle in Java

Beginner
⏱️ 5 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
Nested Loops

What You’ll Learn

Print a triangle whose first row is the full reverse run from E to A, then each row drops the leftmost letter: EDCBA, DCBA, CBA, BA, A.

This pairs well with program 6 (ABCDE, BCDE, ...). Here everything moves toward A instead.

⭐ Pattern Output

When you run the program with rows = 5:

Output
EDCBA
DCBA
CBA
BA
A
1

Complete Java Program

Fixed rows = 5 version. The outer loop sets the row’s starting letter and the inner loop prints down to A.

Java
public class Main {
    public static void main(String[] args) {
        char high = 'E';

        for (char start = high; start >= 'A'; start--) {
            for (char ch = start; ch >= 'A'; ch--) {
                System.out.print(ch);
            }
            System.out.println();
        }
    }
}

🧠 How It Works

1

Outer loop chooses the row start

char high = 'E' anchors the first row. for (char start = high; start >= 'A'; start--) moves the leftmost letter from E down to A.

Outer
2

Inner loop prints down to A

For each row, print letters from start down to 'A' by decrementing the char.

Inner
3

Row length shrinks

Each time start decreases, ch >= 'A' spans one fewer letter, so widths are 5, 4, 3, 2, 1 for the five-row demo.

5, 4, 3, 2, 1
4

Newline per row

System.out.println() after the inner loop keeps each descending run on its own line. Generalize with high = (char)('A' + rows - 1) as in the Scanner example.

println
=

Total work

n(n + 1)/2 prints — O(n²) time, O(1) extra space. Each row is a contiguous reverse suffix from a moving peak down to 'A'.

2

Variation — User Input Version

Compute the top letter as high = (char)('A' + rows - 1) and then print down to A:

Java
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter the number of rows (max 26): ");
        int rows = sc.nextInt();

        rows = Math.max(1, Math.min(rows, 26));
        char high = (char) ('A' + rows - 1);

        for (char start = high; start >= 'A'; start--) {
            for (char ch = start; ch >= 'A'; ch--) {
                System.out.print(ch);
            }
            System.out.println();
        }

        sc.close();
    }
}

💡 Tips for Enhancement

Try These

  • Use lowercase letters by switching to 'a' as the base
  • Compare with program 2 to see what happens when you reset the start letter each row
  • Try printing with spaces for a right-aligned version
  • Replace letters with numbers to practice the same loop idea

Avoid

  • Letting rows exceed 26 without handling wrap-around
  • Using ++ loops when you want reverse alphabetical order
  • Printing without a newline after each row

Key Takeaways

1

Outer loop controls the row’s starting letter (E, D, C, ...).

2

Inner loop prints from the row start down to A.

3

Row lengths shrink by one each line: n, n-1, ..., 1.

4

Total printed characters are n(n+1)/2, so runtime is O(n²).

❓ Frequently Asked Questions

Because the inner loop always prints down to 'A', so the last printed character is always A.
Program 6 prints forward slices ending at E. Program 7 prints reverse slices ending at A.
O(n²) for n rows.

Next: Java Alphabet Pattern 8

Continue to Program 8 for the next alphabet pattern in Java.

Program 8 →
Did you know?

This pattern is symmetric to Program 6: Program 6 keeps the right edge fixed at E; Program 7 keeps the right edge fixed at A.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful