Java Repeating Alphabet Triangle Pattern

Beginner
7 min read
Updated: Sep 2026
3 programs
Live preview

What Is This Pattern?

A repeating alphabet triangle grows by one character each row, but every character on that row is the same letter — the letter advances with the row.

Remember
Rule: for letter i from A to last,
      print i with growing width 1, 2, 3, …

A
BB
CCC
DDDD
EEEEE     ← 5 rows

Unlike Program 1 (A, AB, ABC), letters do not step across the row — you print the outer loop letter inside the inner loop. The reverse twin is Program 10 (E, DD, CCC, …).

How to Solve It

Two ways to emit the same shape — start with nested char loops, then optionally shorten with String.repeat.

MethodIdeaBest for
Nested char loopsOuter = letter; inner = growing width; print outer letterLearning, interviews, exams
String.valueOf(ch).repeat(n)Build a whole repeated-letter row in one callShorter demos once loops click (Java 11+)

Pseudocode

Pseudocode
for i from 'A' to lastLetter:
    for j from 'A' to i:
        print i (no newline)
    print newline

Cheat sheet

GoalPattern
Advance letterfor (char i = 'A'; i <= last; i++)
Grow widthfor (char j = 'A'; j <= i; j++)
Uniform rowSystem.out.print(i); — print i, not j
End the rowSystem.out.println();
Letter from row indexchar ch = (char)('A' + row - 1);
One-line shortcutSystem.out.println(String.valueOf(ch).repeat(row));
Reverse twinProgram 10 (E, DD, CCC, …)

Printing Letters vs Starting a New Line

APIEffectUse for
System.out.printStays on the same lineEach letter on the row
System.out.printlnEnds the current lineAfter the inner loop finishes a row

Print letters without a newline, then end the row once.

Live Preview

Change the row count and the repeating triangle updates instantly — including the triangular letter total.

Whole numbers from 1 to 10. Tap a chip or type a value — the preview redraws as you go.

Live result 5 rows · last E · 15 letters
A
BB
CCC
DDDD
EEEEE

Worked Walkthrough — rows = 4

Trace each outer-loop letter as i advances from 'A' to 'D'.

Letter iInner runsPrinted rowRepeats
'A'1A1
'B'2BB2
'C'3CCC3
'D'4DDDD4

Total letter prints: 1 + 2 + 3 + 4 = 10 = 4×5/2 — same triangular count as Program 1.

Java Programs

Three complete programs: fixed last letter, Scanner input, and a String.repeat shortcut. Use View Output to reveal sample results.

Example 1 — Fixed from 'A' to 'E'

Hard-coded last letter — outer loop picks the letter; inner loop only controls the repeat count.

Java
public class RepeatingAlphabetTriangle {
    public static void main(String[] args) {
        for (char i = 'A'; i <= 'E'; i++) {
            for (char j = 'A'; j <= i; j++) {
                System.out.print(i);
            }
            System.out.println();
        }
    }
}

How It Works

1. Outer loop picks the row letter. i runs from 'A' to 'E' — one letter per row.

2. Inner loop only counts. j runs from 'A' to i, so the width grows 1, 2, 3, …

3. Print i, not j. That keeps every character on the row the same. Printing j would rebuild Program 1.

When i = 'C' the inner loop runs three times and you get CCC.

Example 2 — Row Count Input

Compute the row letter from the row number. Prefer checking hasNextInt() before nextInt() in real apps.

Java
import java.util.Scanner;

public class RepeatingAlphabetTriangleInput {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        System.out.print("Enter the number of rows: ");
        int rows = sc.nextInt();

        for (int row = 1; row <= rows; row++) {
            char ch = (char) ('A' + row - 1);
            for (int col = 1; col <= row; col++) {
                System.out.print(ch);
            }
            System.out.println();
        }

        sc.close();
    }
}

How It Works

1. Prompt and read. Ask for a row count, then store it with sc.nextInt().

2. Map row index to a letter. ch = (char)('A' + row - 1) — for row = 3, ch is 'C'.

3. Repeat ch exactly row times. Same uniform-row idea as Example 1, expressed with integer bounds.

4. Safer input tip. Unchecked nextInt() throws on letters. Prefer:

Safer input
if (!sc.hasNextInt()) {
    System.out.println("Enter a whole number from 1 to 26.");
    return;
}
int rows = sc.nextInt();
if (rows < 1 || rows > 26) {
    System.out.println("Enter a whole number from 1 to 26.");
    return;
}

Example 3 — String.valueOf(ch).repeat(row)

Build each repeated-letter row in one call — same shape, no explicit inner letter loop (Java 11+).

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

        for (int row = 1; row <= rows; row++) {
            char ch = (char) ('A' + row - 1);
            System.out.println(String.valueOf(ch).repeat(row));
        }
    }
}

How It Works

1. One outer loop. Still walk row from 1 to rows and map it to a letter.

2. Build the row. String.valueOf(ch).repeat(row) creates a string of length row filled with ch.

3. Print and advance. println prints that string and ends the line.

Learn the two-loop version first (Examples 1–2) so you can explain both bounds; treat this as a polish shortcut afterward.

Edge Cases & Pitfalls

Check these before calling the solution done.

print j

Program 1 by mistake

If you print j instead of i, letters step across the row (A, AB, ABC…). Always print the outer-loop letter.

println early

Column of letters

If println is inside the inner loop, each letter lands on its own line. Use print for letters; println only after the inner loop.

Wrong width

Rectangle, not triangle

Inner bound must grow with the row (j <= i or col <= row). A fixed inner bound prints a filled rectangle.

rows = 1

Single A

Output is just A on one line — a good sanity check.

rows > 26

Beyond Z

Cap or reject — the row letter leaves the alphabet. Keep rows in 1…26 for A–Z demos.

Bad Scanner

Use hasNextInt

Unchecked nextInt() throws on letters — prefer hasNextInt() and clamp to 1…26.

Time and Space Complexity

ProgramTimeExtra space
Nested loops (Examples 1–2)O(n²)O(1)
String.repeat (Example 3)O(n²)O(n) per temporary row string

Total letters printed = 1 + 2 + … + n = n(n+1)/2, which is still quadratic in n.

Key Takeaways

  • Rule: one letter per row; width grows 1, 2, 3, …
  • Print the outer letter: the inner loop only counts — print i, not j.
  • Break the row: call println only after the inner loop.
  • Complexity: O(n²) time; O(1) extra space for nested loops.

One line: for each letter i, print i a growing number of times, then println.

Frequently Asked Questions

Because the inner loop prints the outer-loop character (i) every time. The inner counter only controls how many times to print, not which character to print.
Then letters would change across the row (A, AB, ABC…), which is Program 1 — not a repeating-letter triangle.
On the third row the row letter is C, and the inner loop runs three times, printing C each time.
Program 1 prints stepping letters across each row (A, AB, ABC). This pattern keeps one letter per row and only grows the repeat count (A, BB, CCC).
Program 10 uses the same growing widths but letters count downward (E, DD, CCC…). This pattern counts upward (A, BB, CCC…).
System.out.print stays on the same line. System.out.println ends the current line. Letters use print; the row break uses println after the inner loop.
O(n²) for n rows, because total printed characters are n(n+1)/2.
Yes. System.out.println(String.valueOf(ch).repeat(row)) prints a full repeated-letter row in one call (Java 11+). Nested loops are better for learning; String.repeat is a handy shortcut later.

Did you know?

Each row prints the same letter repeatedly: row 1 prints A once, row 2 prints B twice, row 3 prints C three times. Print the outer loop letter inside the inner loop so the row stays uniform. The reverse twin is Program 10.

Next: Reverse Repeating Triangle

Same growing widths, letters counting down — E, DD, CCC, DDDD…

Program 10 tutorial →

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.

12 people found this page helpful