Increasing Suffix Number Pattern in Java

Beginner
⏱️ 8 min read
📚 Updated: Aug 2026
🎯 3 Code Examples
🚀 Live Preview
Nested Loops i→rows

What You’ll Learn

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.

Shape Rule

i..rows per row

Row 1 prints 5, row 2 prints 45, row 3 prints 345, growing until the full line 12345.

Outer Loop

rows..1

for (i = rows; i >= 1; i--) picks the starting digit for each row.

Inner Loop

Start at i

for (j = i; j <= rows; j++) prints digits from i through rows.

print vs println

Same line / next line

Digits use System.out.print(j); end each row with System.out.println().

Live Preview

1–20 rows

Pick a row count and draw the increasing suffix pattern instantly in the browser.

O(n²)

Complexity

Total digit prints = n(n+1)/2; extra memory stays O(1).

Introduction

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.

Why it matters?

It teaches how reversing the outer loop order reshapes Program 2’s output — a key step after Program 5.

Key Highlights

Row Start = i

On row i, print digits i through rows.

Inner Starts at i

for (j = i; j <= rows; j++) — not j = 1.

Print Then Break

System.out.print(j) in the inner loop; System.out.println() after.

Series Foundation

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().

📝 Problem & Approach

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.

Java
// rows = 5 (conceptual shape)
// 5
// 45
// 345
// 2345
// 12345

Inputs & Outputs

ItemTypeDescription
rowsintNumber of triangle lines to print (typically ≥ 1).
Printed outputtextEach row prints i..rows; the first row has one digit, the last row has rows digits.

Minimal workflow

Pseudocode
for i from rows down to 1:
    for j from i to rows:
        print j (no newline)
    print newline

Approach comparison

ApproachIdeaBest for
Nested loopsOuter rows + inner digitsLearning and interviews
Spaced outputSystem.out.print(j + " ")Easier reading per row — Example 3

⚡ Quick Reference

GoalPattern
Walk each rowfor (i = rows; i >= 1; i--)
Print digits i..rowsfor (j = i; j <= rows; j++) System.out.print(j);
End the rowSystem.out.println();
Spaced digitsSystem.out.print(j + " ")
Program 2 contrastProgram 2 outer i = 1..rows; Program 6 outer i = rows..1
Program 5 contrastProgram 5 uses inner j = 1..i; Program 6 uses inner j = i..rows

📋 Outer Loop vs Inner Loop vs Output Style

How descending outer loop and inner j = i..rows work together.

Outer loop
for (i = rows; i >= 1; i--)

Counts down the starting digit — shortest row prints first.

Inner loop
for (j = i; j <= rows; j++)

Prints from current start i up to rows.

Spaced output
print(j + " ")

Adds spaces between digits — see Example 3.

Learning tip
trace i=3

Dry-run when i = 3: prints 345 on that row.

Context

When This Pattern Shows Up

Reach for this pattern when teaching how the inner loop start value changes the shape.

  1. After Program 5

    Natural follow-up after the ascending triangle — now the suffix grows on the left.

  2. Nested-loop warm-up

    Outer/inner bound practice with an immediate visual check.

  3. Console I/O practice

    Combine loops with Scanner for a flexible row count.

  4. Gateway to variants

    Compare Program 2 (same inner loop, outer counts up) and Program 7 (reverse count) next.

  5. Not a UI layout tool

    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.

🔮 Live Preview

Enter a row count and draw the increasing suffix pattern in the browser.

Try 5, 7, or 10. Larger values still work up to 20.

Live result
Press "Draw pattern".

Examples Gallery

Three complete Java programs — fixed rows = 5, Scanner input, and a spaced-output variant. Click View Output to reveal sample console results.

📚 Getting Started

Print five rows of the increasing suffix pattern with nested loops.

Example 1 — Fixed rows = 5

Hard-coded height — ideal for first demos and screenshots.

Java
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();
        }
    }
}

How It Works

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.

📈 Practical Variant

Let the user choose the height at runtime.

Example 2 — User Input Version

Read the row count with sc.nextInt() (call sc.hasNextInt() first in real apps).

Java
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();
    }
}

How It Works

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.

⚡ Formatting Variant

Add spaces between digits for easier reading.

Example 3 — Spaced Output

Print a space after each digit with print(j + " ").

Java
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();
        }
    }
}

How It Works

Same j = i..rows logic with descending outer loop; only the output format adds spaces between digits.

🧠 How the Algorithm Prints Rows

1

Set up

System.out is built in; use Scanner when reading input. Set rows (fixed or from input).

Setup
2

Outer loop (rows)

for (i = rows; i >= 1; i--) selects the starting digit for each row.

Row
3

Inner loop (digits)

for (j = i; j <= rows; j++) prints digits i..rows with System.out.print(j).

Digits
4

New line

System.out.println() ends the row so the next outer iteration starts fresh.

Break
=

Increasing suffix pattern complete

Total digit prints: 1+2+…+n = n(n+1)/2O(n²) time, O(1) extra memory.

🔎 Worked Walkthrough — row i = 3 (when rows = 5)

Trace outer-loop value i = 3 and the inner j range on that row.

jActionRow so far
3print 33
4print 434
5print 5345

After the inner loop, println() moves to the next row (i = 2 will print 2345).

Use Cases

Where this tiny pattern (and its loop structure) shows up beyond the homework prompt.

1. Teaching Nested Loops

Clearest visual proof that outer and inner bounds interact.

Example: change j <= rows and watch the shape change.

2. Pattern Series Base

Foundation for inverted, pyramid, diamond, and hollow variants.

Example: flip outer loop to count up and compare with Program 2.

3. Console Formatting Drills

Practice System.out.print vs row newline without complex math.

Example: put System.out.println() inside the inner loop by mistake.

4. Character Substitution

Swap digits for letters, stars, or spaced output once the loop works.

Example: print j + " " for spaced digits on each row.

5. Complexity Intuition

Triangular totals make O(n²) concrete for beginners.

Example: count printed digits for n = 10 → 55.

6. Input Validation Labs

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.

Advantages

Why this pattern earns a permanent spot in beginner Java courses.

  1. 1. Instant Visual Feedback

    Wrong bounds show up immediately as a broken staircase.

  2. 2. Minimal Concepts

    Only loops and console output — no arrays or math libraries.

  3. 3. Easy to Extend

    Invert, center, hollow, or change the fill character with small edits.

  4. 4. O(1) Extra Memory

    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.

Usage Tips

Small habits that keep number-pattern code clean.

  1. 1. Name Bounds Clearly

    Use rows (or n) and keep i/j for row/column — or rename to row/col.

  2. 2. Prefer Scanner

    Call sc.hasNextInt() so bad input does not leave rows uninitialized.

  3. 3. Keep System.out.println() Outside

    Only call System.out.println() after the inner loop finishes the row.

  4. 4. Count Outer Loop Down

    for (i = rows; i >= 1; i--) prints the shortest row first — key to this pattern.

  5. 5. Inner Loop Starts at i

    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.

Common Pitfalls

Mistakes that commonly break increasing suffix number patterns.

  1. 1. Newline Inside the Inner Loop

    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.

  2. 2. Wrong Inner Start

    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++).

  3. 3. Forgetting the Row Break

    Omitting System.out.println() glues every digit onto one endless line.

    → Always end the row after the inner loop.

  4. 4. Unchecked Scanner input

    Letters or empty input leave rows uninitialized.

    → Prefer hasNextInt() and re-prompt on failure.

  5. 5. Off-by-One on 0-Based Loops

    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.

Edge Cases

Check these inputs before calling the solution done.

rows = 1

Single digit row

Output is just 1 on one line.

rows = 0

Empty pattern

Outer loop never runs — print nothing or show a message.

Negative

rows < 0

Treat as invalid; re-prompt instead of silent empty output.

Large n

Many rows

Output grows as n²/2 characters — fine for labs, noisy for huge n.

Bad input

Non-numeric Scanner input

Unchecked Scanner leaves rows unset — call sc.hasNextInt() first.

Fill char

Spaced digits

Try System.out.print(j + " ") for spaces between numbers.

🎯 Practice Problems

Try these variations to lock in the pattern.

1. Compare Program 2

  • Program 2: 12345, 2345… (outer counts up)
  • Review Program 2

2. Flip outer loop

  • Use for (i = 1; i <= rows; i++)
  • Same inner loop — see Program 2 order

3. Next in series

  • Continue with Program 7
  • Growing reverse triangle 1, 21, 321…

4. Spaced output

  • Use System.out.print(j + " ") between digits
  • See Example 3 on this page

Notes

  • Triangular count. Total digit prints for n rows is n(n+1)/2 — hence O(n²) time.
  • System.out.print(j) stays on the line; System.out.println() advances — mix them carefully.
  • Validate rows > 0 for interactive programs; rows = 1 should print a single 1.
  • Compare with Program 2 (outer counts up) and Program 5 (inner j = 1..i).

Quick Takeaway: outer loop i = rows..1, inner loop prints digits i..rows, then break the line.

⏱️ Time and Space Complexity

ProgramTimeExtra space
Nested loops (Examples 1–3)O(n²)O(1)
Spaced output (Example 3)O(n²)O(1)
Wrap Up

🎉 Conclusion

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.

💡 Best Practices

✅ Do

  • Use for (i = rows; i >= 1; i--) in the outer loop
  • Inner: for (j = i; j <= rows; j++) prints digits i..rows
  • Use System.out.print(j) for digits and System.out.println() after each row
  • Validate rows ≥ 1 for interactive programs
  • Call sc.hasNextInt() before using rows
  • State O(n²) time when asked about complexity

❌ Don’t

  • Call System.out.println() inside the inner digit loop
  • Use j = 1 when you meant increasing suffix shape
  • Skip the newline after each row
  • Ignore bad console input in user-facing demos
  • Skip the rows = 1 edge case

Key Takeaways

Knowledge Unlocked

Five things to remember about this increasing suffix pattern

Print the pattern the beginner-friendly way.

5
Core concepts
02

Outer loop

Counts down rows

Code
1 03

Inner start

j = i, not j = 1

Code
04

Newline

Ends each row

I/O
O 05

Complexity

O(n²) time

Analysis

❓ Frequently Asked Questions

On the first iteration i equals rows, so the inner loop prints only rows (just 5). Each next row starts one value earlier, so the line grows on the left.
The outer loop runs i from rows down to 1. For each row i, the inner loop runs j from i to rows and prints j using System.out.print, then prints a newline.
Program 2 prints 12345, then 2345, then 345 (outer loop counts up). Program 6 prints 5, then 45, then 345 (outer loop counts down) — same inner loop, reversed row order.
Program 5 prints 1, 12, 123 (inner loop j = 1..i). Program 6 prints 5, 45, 345 (inner loop j = i..rows with descending outer loop).
Yes. Print System.out.print(j + " ") inside the inner loop — see Example 3.
O(n²) for n rows. Total printed digits are 1+2+...+n = n(n+1)/2.
Use sc.hasNextInt() before sc.nextInt() so bad input does not throw InputMismatchException.
The outer loop never runs, so nothing is printed. Validate and prompt again if you want a clear user message.

Did you Know? 🔊

The 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, …

Continue to Program 7

Move on to the growing reverse number triangle in the Java number-pattern series.

Program 7 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