Reverse Right-Angled Triangle Alphabet Pattern in Java

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

What You’ll Learn

How to print a reverse alphabet right-angled triangle: each row has one more character than the previous row, and letters run backward along the row (E, ED, EDC, ... for 5 rows).

This is the reverse counterpart of program 1, which prints A, AB, ABC, ...

⭐ Pattern Output

When you run the program with rows = 5:

Output
E
ED
EDC
EDCB
EDCBA
1

Complete Java Program

Fixed rows = 5 version. Reset ch to 'E' at the beginning of each row, then print i letters with ch--.

Java
public class Main {
    public static void main(String[] args) {
        int rows = 5;

        for (int i = 1; i <= rows; i++) {
            char ch = 'E';
            for (int j = 1; j <= i; j++) {
                System.out.print(ch--);
            }
            System.out.println();
        }
    }
}

🧠 How It Works

1

Outer loop for rows

Loop i = 1 .. rows. Row i prints exactly i characters.

Outer
2

Reset the starting letter

Set ch = 'E' at the start of each row, so every row begins from the same top letter.

Row prefix
3

Inner loop prints and decrements

for (int j = 1; j <= i; j++) runs i times. System.out.print(ch--) uses postfix decrement: it prints the current char, then steps backward toward 'A'.

Inner
4

Next row

System.out.println() ends the line; the outer loop’s next iteration sets ch = 'E' again so each row starts from the same top letter (for the fixed five-row demo).

println
=

Reverse alphabet triangle

Total printed characters are 1 + 2 + … + n = n(n + 1)/2O(n²) time, O(1) extra space. The variation replaces hard-coded 'E' with top = (char)('A' + rows - 1).

2

Variation — User Input Version

For rows rows, compute the top letter as 'A' + rows - 1, then use it as the starting ch for every row:

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 top = (char) ('A' + rows - 1);

        for (int i = 1; i <= rows; i++) {
            char ch = top;
            for (int j = 1; j <= i; j++) {
                System.out.print(ch--);
            }
            System.out.println();
        }

        sc.close();
    }
}

💡 Tips for Enhancement

Try These

  • Use lowercase letters by starting from 'e' / 'a'
  • Print the forward alphabet triangle using program 1
  • Add spaces between letters for readability
  • Try making a centered alphabet pyramid next

Avoid

  • Hard-coding 'E' when you want a fully dynamic program (compute top)
  • Letting rows > 26 without handling wrap-around
  • Forgetting a newline after each row
  • Closing System.in if you need input later in the same app

Key Takeaways

1

Row i prints i letters, so the triangle widens one character per row.

2

Reset the starting letter at the beginning of each row to keep the pattern shape.

3

Generalize with top = (char)('A' + rows - 1) and print using ch--.

4

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

❓ Frequently Asked Questions

Resetting ch ensures every row begins with the same top letter, so the pattern stays E, ED, EDC, ... instead of continuing the decrement across rows.
Yes. Use 'e' (fixed) or 'a' (dynamic) as the base character instead of 'E' / 'A'.
It’s O(n²) for n rows, because the program prints 1+2+…+n characters overall.

Next: Java Alphabet Pattern 3

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

Program 3 →
Did you know?

System.out.print(ch--) uses the post-decrement value for printing, so you see the letter first, then ch moves to the previous character.

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