Inverted Forward Repeating Triangle in Java

What You’ll Learn
Row width shrinks from five to one, but the letter moves forward each row: AAAAA, BBBB, CCC, DD, E.
Compare program 11 (same inverted shape, letters step down from E) and program 9 (width grows with forward letters).
⭐ Pattern Output
For 5 rows (i from 65 to 69):
AAAAA
BBBB
CCC
DD
EComplete Java Program
Outer i from 65 up to 69. Inner j from 69 down to i; each iteration prints (char) i.
public class Main {
public static void main(String[] args) {
int i, j;
for (i = 65; i <= 69; i++) {
for (j = 69; j >= i; j--) {
System.out.print((char) i);
}
System.out.println();
}
}
}🧠 How It Works
Class and main
Main holds public static void main(String[] args), the program entry point.
Outer loop: forward letter
for (i = 65; i <= 69; i++) walks A, B, C, D, E. That value is what you print on every cell of the row.
Inner loop: shrinking width
for (j = 69; j >= i; j--) runs 69 - i + 1 times. Each time, System.out.print((char) i) repeats the same letter.
New line
System.out.println() ends the row; i++ moves to the next letter (and shorter row).
Fifteen characters for five rows
Same total as programs 9 and 11 — O(n²) for n rows.
Variation — User Input Version
Let base = 65 and top = base + rows - 1. Outer i from base to top; inner j from top down to i. Clamp rows to 1–26:
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));
final int base = 65;
int top = base + rows - 1;
int i, j;
for (i = base; i <= top; i++) {
for (j = top; j >= i; j--) {
System.out.print((char) i);
}
System.out.println();
}
sc.close();
}
}💡 Tips for Enhancement
Try These
charstyle:ch = 'A', outerkfromrowsto1, innerjtokprintingch, thench++after each row- Inverted with descending letters: program 11
- Growing triangle: program 9
- Lowercase: use
base = 97
Avoid
System.out.print((char) j)unless you want letters stepping along the row- Decrementing
ion the outer loop when you need A→E row order
Key Takeaways
Inverted width plus ascending i gives forward letters on a shrinking triangle.
Inner count = top - i + 1 with fixed top = 69 in the five-row demo.
O(n²) characters for n rows.
Dual of program 11; like program 9 with the outer letter loop paired to shrinking widths.
❓ Frequently Asked Questions
i starts at 65 ('A'), and j runs from 69 down to 65—five iterations—each printing (char) i.i descending (E→A) with j from base to i. Program 12 uses outer i ascending (A→E) with j from top down to i.top = 65 + rows - 1, then for (i = 65; i <= top; i++) with inner j from top to i.More Java alphabet patterns
Programs 11 and 12 share the same inverted widths; only whether i counts down from E or up from A changes the letter order.
You can derive the letter without mutating ch: at the start of each outer step, (char) i already is the row’s symbol; the inner loop only counts how many times to print it.
12 people found this page helpful
