Java Alphabet Pattern Programs

Beginner
6 min read
Updated: Nov 2026
3 examples
char + print

Definition and Usage

A Java alphabet pattern is a console program that prints letters in rows. The outer for loop chooses the row. The inner for loop prints each char with System.out.print, then System.out.println ends that row.

A char is a 16-bit Unicode code unit, so letter++ walks A, B, C… Adding an int promotes the sum: 'A' + col is an int, and print writes those digits (65, 66, 67). Cast with (char)('A' + col) when the shape should stay in A–Z.

Print a char, not the sum.

System.out.print(letter) writes the character. System.out.print('A' + col) writes the integer code unless you cast back to char first.

Java Syntax

The same three pieces show up in every program below: a char loop, System.out.print, and println after the inner loop.

Java
for (char end = 'A'; end <= 'E'; end++) {
    for (char letter = 'A'; letter <= end; letter++)
        System.out.print(letter);  // same line
    System.out.println();          // end the row
}

How Java Prints a Letter

Map each part of the console shape to a Java type or call.

PieceJavaWhat it does
Letterchar letter = 'A';16-bit code unit that print writes as a character
Next letterletter++A becomes B on the same row
Jump(char)('A' + col)'A' + col is an int; the cast makes it a letter again
Same lineSystem.out.print(letter)No newline between letters
New rowSystem.out.println()Finish the row
IndentSystem.out.print(' ')Leading spaces for pyramids
A–Z sliceletters.substring(0, n)Same growing row from a String

Java Examples

Three programs. Each one changes only the Java that picks the letter or the space.

Example 1 — Grow a row with a char loop

The outer char is the last letter on the row. The inner loop restarts at 'A'.

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

How It Works

  1. end runs from 'A' to 'E', one row per letter.
  2. The inner loop prints 'A' through end, so the row is A…end.
  3. print stays on the line; println starts the next row.

Example 2 — Cast the sum back to char

Skip the running char. Compute the letter from the column index.

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

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

How It Works

  1. 'A' + col promotes to int.
  2. The (char) cast turns that sum back into a letter before print sees it.
  3. Without the cast, the same line prints 65, 6566, and so on.

Example 3 — Indent with System.out.print(' ')

Print spaces before the letters so the triangle sits on the right.

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

        for (int row = 1; row <= rows; row++) {
            for (int space = 1; space <= rows - row; space++)
                System.out.print(' ');

            for (int col = 0; col < row; col++)
                System.out.print((char) ('A' + col));

            System.out.println();
        }
    }
}

How It Works

  1. The first inner loop prints rows - row space characters.
  2. The second loop prints letters with the same (char) cast.
  3. Fewer spaces and more letters on each later row pull the shape right.

34 Java Alphabet Pattern Programs

Each card is a full Java program: nested for loops, char math, and the letters System.out.print writes. Open one for the walkthrough.

Alphabet Pattern 1
Alphabet Pattern 2
Alphabet Pattern 3
Alphabet Pattern 4
Alphabet Pattern 5
Alphabet Pattern 6
Alphabet Pattern 7
Alphabet Pattern 8
Alphabet Pattern 9
Alphabet Pattern 10
Alphabet Pattern 11
Alphabet Pattern 12
Alphabet Pattern 13
Alphabet Pattern 14
Alphabet Pattern 15
Alphabet Pattern 16
Alphabet Pattern 17
Alphabet Pattern 18
Alphabet Pattern 19
Alphabet Pattern 20
Alphabet Pattern 21
Alphabet Pattern 22
Alphabet Pattern 23
Alphabet Pattern 24
Alphabet Pattern 25
Alphabet Pattern 26
Alphabet Pattern 27
Alphabet Pattern 28
Alphabet Pattern 29
Alphabet Pattern 30
Alphabet Pattern 31
Alphabet Pattern 32
Alphabet Pattern 33
Alphabet Pattern 34

Frequently Asked Questions

In Java, 'A' + col is an int. Binary numeric promotion widens the char before the addition, so the sum is 65, 66, 67… and print writes those digits. Cast with (char)('A' + col) and print writes the letter.
System.out.print stays on the same line, which is how each letter in a row is placed. System.out.println ends the row. Call println once after the inner loop.
Char math continues past 'Z' into other characters. For A–Z demos, keep rows between 1 and 26. With Scanner, call hasNextInt before nextInt so a bad token does not throw InputMismatchException.
Yes. Store "ABCDEFGHIJKLMNOPQRSTUVWXYZ" and call substring(0, length) for a row that always starts at A. Nested char loops are the skill these programs teach; substring is a shortcut once the shape is clear.

Next: Alphabet Pattern 1

A full Java walkthrough of the right-angled letter triangle, from 'A' through System.out.println.

Alphabet Pattern 1 →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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.

28 people found this page helpful