Shape Rule
i..rows per row
Row 1 prints 5, row 2 prints 45, row 3 prints 345, growing until the full line 12345.

The increasing suffix number pattern grows each row by one digit on the left — a natural step after the ascending triangle in Program 5. This tutorial covers the shape rule, descending outer loop, live preview, algorithm steps, worked Java examples, edge cases, and complexity.
i..rows per row
Row 1 prints 5, row 2 prints 45, row 3 prints 345, growing until the full line 12345.
rows..1
for (i = rows; i >= 1; i--) picks the starting digit for each row.
Start at i
for (j = i; j <= rows; j++) prints digits from i through rows.
Same line / next line
Digits use System.out.print(j); end each row with System.out.println().
1–20 rows
Pick a row count and draw the increasing suffix pattern instantly in the browser.
Complexity
Total digit prints = n(n+1)/2; extra memory stays O(1).
An increasing suffix number pattern starts with a single digit and adds one more digit on the left each row. With rows = 5, the output is 5, 45, 345, 2345, 12345.
In Java the outer loop counts down from rows to 1, the inner loop prints j from i to rows, then System.out.println() moves to the next line.
It teaches how reversing the outer loop order reshapes Program 2’s output — a key step after Program 5.
On row i, print digits i through rows.
for (j = i; j <= rows; j++) — not j = 1.
System.out.print(j) in the inner loop; System.out.println() after.
Follow Program 5; compare with Program 2; continue to Program 7 (growing reverse triangle).
In short: for each row i from rows down to 1, print digits i..rows with System.out.print(j), then call System.out.println().
Given a positive integer rows, print an increasing suffix pattern: each row i shows digits from i through rows, with the outer loop counting from rows down to 1.
// rows = 5 (conceptual shape)
// 5
// 45
// 345
// 2345
// 12345 | Item | Type | Description |
|---|---|---|
rows | int | Number of triangle lines to print (typically ≥ 1). |
| Printed output | text | Each row prints i..rows; the first row has one digit, the last row has rows digits. |
for i from rows down to 1:
for j from i to rows:
print j (no newline)
print newline | Approach | Idea | Best for |
|---|---|---|
| Nested loops | Outer rows + inner digits | Learning and interviews |
| Spaced output | System.out.print(j + " ") | Easier reading per row — Example 3 |
| Goal | Pattern |
|---|---|
| Walk each row | for (i = rows; i >= 1; i--) |
Print digits i..rows | for (j = i; j <= rows; j++) System.out.print(j); |
| End the row | System.out.println(); |
| Spaced digits | System.out.print(j + " ") |
| Program 2 contrast | Program 2 outer i = 1..rows; Program 6 outer i = rows..1 |
| Program 5 contrast | Program 5 uses inner j = 1..i; Program 6 uses inner j = i..rows |
How descending outer loop and inner j = i..rows work together.
for (i = rows; i >= 1; i--)Counts down the starting digit — shortest row prints first.
for (j = i; j <= rows; j++)Prints from current start i up to rows.
print(j + " ")Adds spaces between digits — see Example 3.
trace i=3Dry-run when i = 3: prints 345 on that row.
Reach for this pattern when teaching how the inner loop start value changes the shape.
Natural follow-up after the ascending triangle — now the suffix grows on the left.
Outer/inner bound practice with an immediate visual check.
Combine loops with Scanner for a flexible row count.
Compare Program 2 (same inner loop, outer counts up) and Program 7 (reverse count) next.
This is a console teaching pattern — not how you build modern app screens.
Key benefit: one small program that locks in nested loops, output sequencing, and O(n²) thinking.
Enter a row count and draw the increasing suffix pattern in the browser.
Three complete Java programs — fixed rows = 5, Scanner input, and a spaced-output variant. Click View Output to reveal sample console results.
Print five rows of the increasing suffix pattern with nested loops.
rows = 5Hard-coded height — ideal for first demos and screenshots.
public class IncreasingSuffixPattern {
public static void main(String[] args) {
int rows = 5;
for (int i = rows; i >= 1; i--) {
for (int j = i; j <= rows; j++) {
System.out.print(j);
}
System.out.println();
}
}
} When i = 5, the inner loop prints only 5. When i = 4, it prints 45, and so on until i = 1 prints 12345. System.out.println() after the inner loop starts the next row.
Let the user choose the height at runtime.
Read the row count with sc.nextInt() (call sc.hasNextInt() first in real apps).
import java.util.Scanner;
public class IncreasingSuffixPatternInput {
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 i = rows; i >= 1; i--) {
for (int j = i; j <= rows; j++) {
System.out.print(j);
}
System.out.println();
}
sc.close();
}
} Same nested-loop core as Example 1; only the source of rows changes. Non-numeric input leaves rows unset if you ignore Scanner’s return value — always check it in safer labs.
Add spaces between digits for easier reading.
Print a space after each digit with print(j + " ").
public class IncreasingSuffixPatternSpaced {
public static void main(String[] args) {
int rows = 5;
for (int i = rows; i >= 1; i--) {
for (int j = i; j <= rows; j++) {
System.out.print(j + " ");
}
System.out.println();
}
}
} Same j = i..rows logic with descending outer loop; only the output format adds spaces between digits.
System.out is built in; use Scanner when reading input. Set rows (fixed or from input).
for (i = rows; i >= 1; i--) selects the starting digit for each row.
for (j = i; j <= rows; j++) prints digits i..rows with System.out.print(j).
System.out.println() ends the row so the next outer iteration starts fresh.
Total digit prints: 1+2+…+n = n(n+1)/2 — O(n²) time, O(1) extra memory.
i = 3 (when rows = 5)Trace outer-loop value i = 3 and the inner j range on that row.
j | Action | Row so far |
|---|---|---|
| 3 | print 3 | 3 |
| 4 | print 4 | 34 |
| 5 | print 5 | 345 |
After the inner loop, println() moves to the next row (i = 2 will print 2345).
Where this tiny pattern (and its loop structure) shows up beyond the homework prompt.
Clearest visual proof that outer and inner bounds interact.
Example: change j <= rows and watch the shape change.
Foundation for inverted, pyramid, diamond, and hollow variants.
Example: flip outer loop to count up and compare with Program 2.
Practice System.out.print vs row newline without complex math.
Example: put System.out.println() inside the inner loop by mistake.
Swap digits for letters, stars, or spaced output once the loop works.
Example: print j + " " for spaced digits on each row.
Triangular totals make O(n²) concrete for beginners.
Example: count printed digits for n = 10 → 55.
Pair the pattern with Scanner return checks and positive-row checks.
Example: reject rows <= 0 and re-prompt.
Pro Tip: when an interviewer asks for patterns, explain the outer/inner roles first — then write the loops. The story matters as much as the code.
Why this pattern earns a permanent spot in beginner Java courses.
Wrong bounds show up immediately as a broken staircase.
Only loops and console output — no arrays or math libraries.
Invert, center, hollow, or change the fill character with small edits.
Streaming output needs no storage beyond loop counters.
Pro Tip: learn the descending outer loop first; then try Scanner input and spaced output in Example 3.
Small habits that keep number-pattern code clean.
Use rows (or n) and keep i/j for row/column — or rename to row/col.
ScannerCall sc.hasNextInt() so bad input does not leave rows uninitialized.
Only call System.out.println() after the inner loop finishes the row.
for (i = rows; i >= 1; i--) prints the shortest row first — key to this pattern.
for (j = i; j <= rows; j++) — trace rows = 3 on paper before larger demos.
Pro Tip: if the output is a vertical list of single digits, you almost certainly put System.out.println() inside the inner loop.
Mistakes that commonly break increasing suffix number patterns.
Each digit lands on its own line — you get a column, not a triangle.
→ Use System.out.print(j) for digits; System.out.println() only after the inner loop.
j = 1 prints digits from 1 each row — a different shape, not the increasing suffix pattern.
→ For this shape, keep for (j = i; j <= rows; j++).
Omitting System.out.println() glues every digit onto one endless line.
→ Always end the row after the inner loop.
Letters or empty input leave rows uninitialized.
→ Prefer hasNextInt() and re-prompt on failure.
Switching to i = 0 without adjusting the inner bound prints an empty first row or wrong counts.
→ If 0-based, start inner at j = i and end at rows - 1 or adjust bounds.
Check these inputs before calling the solution done.
Output is just 1 on one line.
Outer loop never runs — print nothing or show a message.
rows < 0Treat as invalid; re-prompt instead of silent empty output.
Output grows as n²/2 characters — fine for labs, noisy for huge n.
Unchecked Scanner leaves rows unset — call sc.hasNextInt() first.
Try System.out.print(j + " ") for spaces between numbers.
Try these variations to lock in the pattern.
12345, 2345… (outer counts up)for (i = 1; i <= rows; i++)1, 21, 321…System.out.print(j + " ") between digitsn(n+1)/2 — hence O(n²) time.System.out.print(j) stays on the line; System.out.println() advances — mix them carefully.rows > 0 for interactive programs; rows = 1 should print a single 1.j = 1..i).Quick Takeaway: outer loop i = rows..1, inner loop prints digits i..rows, then break the line.
| Program | Time | Extra space |
|---|---|---|
| Nested loops (Examples 1–3) | O(n²) | O(1) |
| Spaced output (Example 3) | O(n²) | O(1) |
The increasing suffix number pattern is a compact nested-loop lesson: outer loop counts down while the inner loop prints digits i through rows. Master the fixed-rows version, then try user input and spaced output.
Practice the three examples above, then continue to Program 7 for the growing reverse number triangle.
Row i prints i..rows — keep System.out.print(j) for digits and System.out.println() for the break, and validate row counts when reading input.
for (i = rows; i >= 1; i--) in the outer loopfor (j = i; j <= rows; j++) prints digits i..rowsSystem.out.print(j) for digits and System.out.println() after each rowrows ≥ 1 for interactive programssc.hasNextInt() before using rowsSystem.out.println() inside the inner digit loopj = 1 when you meant increasing suffix shaperows = 1 edge casePrint the pattern the beginner-friendly way.
Row i prints i..rows
DefinitionCounts down rows
Codej = i, not j = 1
CodeEnds each row
I/OO(n²) time
AnalysisThe outer loop starts at rows and counts down — each row prints digits from i through rows, so the suffix grows on the left: 5, 45, 345, …
Move on to the growing reverse number triangle in the Java number-pattern series.
12 people found this page helpful