Java Number Triangle Pattern (Starting from 11)

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

What Is This Pattern?

An increasing number triangle from 11 prints row i with i values computed as 9 + i + j — so the first cell is always 11, and each row adds one more number.

Remember
Rule: for i from 1 to rows,
      for j from 1 to i:
        print (9 + i + j) + " "

11
12 13
13 14 15
14 15 16 17
15 16 17 18 19     ← rows = 5

Unlike Program 33 (formula i + j − 1, starts at 1), here the base offset 9 shifts the whole triangle to start at 11.

How to Solve It

Grow i from 1 to rows; for each row print j = 1..i values of base + i + j.

MethodIdeaBest for
Fixed base 9Print (9 + i + j) + " " in nested loopsLearning, interviews, exams
Custom baseReplace 9 with a baseVal from inputWhen you want any starting offset

Pseudocode

Pseudocode
for i from 1 to rows:
    for j from 1 to i:
        print (9 + i + j) + " "
    print newline

Cheat sheet

GoalPattern
Walk rowsfor (int i = 1; i <= rows; i++)
Print i valuesfor (int j = 1; j <= i; j++)
Compute valueSystem.out.print((9 + i + j) + " ");
End the rowSystem.out.println();
Custom baseSystem.out.print((baseVal + i + j) + " ");

Printing Numbers vs Starting a New Line

APIEffectUse for
System.out.printStays on the same lineEach number plus trailing space
System.out.printlnEnds the current lineAfter the inner loop finishes

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

Live Preview

Change the row count and the increasing triangle updates instantly.

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

Live result rows = 5 · 15 values
11
12 13
13 14 15
14 15 16 17
15 16 17 18 19

Worked Walkthrough — rows = 5

Trace i, the inner range j = 1..i, and 9 + i + j for each cell.

iValues of 9 + i + jPrinted row
11111
212, 1312 13
313, 14, 1513 14 15
414 … 1714 15 16 17
515 … 1915 16 17 18 19

Total values = 1 + 2 + … + 5 = 15 — the triangular number n(n+1)/2.

Java Programs

Three complete programs: fixed rows = 5, custom base and rows via Scanner, and a compact dry-run. Use View Output to reveal sample results.

Example 1 — Fixed rows = 5

Hard-coded size — formula 9 + i + j with a trailing space.

Java
public class IncreasingFrom11 {
    public static void main(String[] args) {
        for (int i = 1; i <= 5; i++) {
            for (int j = 1; j <= i; j++)
                System.out.print((9 + i + j) + " ");
            System.out.println();
        }
    }
}

How It Works

1. Outer loop grows. i runs from 1 to 5 — one longer row each time.

2. Inner loop prints i values. For each j from 1 to i, print 9 + i + j plus a space.

3. Break the row. Call println once after the inner loop.

When i = 1: 9+1+1 = 11. When i = 3: 13 14 15.

Example 2 — Custom Base and Rows

Read rows and baseVal at runtime. Same nested loops; formula uses baseVal.

Java
import java.util.Scanner;

public class IncreasingFrom11Input {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter rows: ");
        int rows = sc.nextInt();
        System.out.print("Enter base: ");
        int baseVal = sc.nextInt();
        if (rows < 1) return;

        for (int i = 1; i <= rows; i++) {
            for (int j = 1; j <= i; j++)
                System.out.print((baseVal + i + j) + " ");
            System.out.println();
        }
        sc.close();
    }
}

How It Works

1. Prompt twice. Read rows and baseVal; exit early if rows is less than 1.

2. Same formula. Only the source of the base and height changes from literals to input.

3. Safer input tip. Prefer:

Safer input
if (!sc.hasNextInt()) {
    System.out.println("Enter an integer.");
    return;
}
int rows = sc.nextInt();
if (!sc.hasNextInt()) {
    System.out.println("Enter an integer.");
    return;
}
int baseVal = sc.nextInt();

Example 3 — Compact rows = 3

Same nested-loop formula as Example 1 — smaller size for paper tracing.

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

        for (int i = 1; i <= rows; i++) {
            for (int j = 1; j <= i; j++)
                System.out.print((9 + i + j) + " ");
            System.out.println();
        }
    }
}

How It Works

1. Same structure. Nested loops and 9 + i + j — only rows changes from 5 to 3.

2. Three rows. 11, then 12 13, then 13 14 15.

3. Dry-run first. Trace i = 1..3 on paper before coding the full rows = 5 demo.

Edge Cases & Pitfalls

Check these before calling the solution done.

println inside

Column of numbers

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

Wrong formula

Off-by-base

Using i + j alone starts at 2. Using i + j − 1 starts at 1 (Program 33). Keep 9 + i + j for a start of 11.

Missing space

Glued digits

Omitting + " " concatenates numbers like 1213 instead of 12 13.

rows = 1

Single value

Output is just 11 (with base 9).

rows ≤ 0

Empty output

The outer loop never runs — print nothing or show a message.

Bad input

Use hasNextInt

nextInt() throws on letters — prefer hasNextInt() for both rows and baseVal.

Time and Space Complexity

ProgramTimeExtra space
Increasing from 11 (Examples 1–3)O(n²)O(1)

Total values = n(n+1)/2 — still quadratic. Only loop counters are stored.

Key Takeaways

  • Rule: for each i, print j = 1..i values of 9 + i + j.
  • Base offset: 9 makes the first cell 11; swap it for any starting shift.
  • Break the row: call println only after the inner loop.
  • Complexity: O(n²) time; O(1) extra space.

One line: for i = 1..rows, print (9 + i + j) + " " for j = 1..i, then println().

Frequently Asked Questions

Because the printed value is 9 + i + j. On the first row i = 1 and j = 1, so 9 + 1 + 1 = 11.
It is a base offset. Change 9 to any base value to shift the entire triangle — see Example 2.
Program 32 uses 9 + i + j (starts at 11). Program 33 uses i + j - 1 (starts at 1).
System.out.print((9 + i + j) + " ") keeps values separated on the same row. System.out.println() ends the row.
Replace 5 with rows in the outer loop bound — see Example 2.
O(n²) for n rows because total prints are 1 + 2 + … + n = n(n+1)/2.
Use sc.hasNextInt() before sc.nextInt() — see Example 2 notes.
Yes — System.out.print((baseVal + i + j) + " ") lets the user pick any starting offset.

Did you know?

Each printed value is computed as 9 + i + j. Row i = 1 prints 11; row i = 2 prints 12 and 13 — a left-shifted increasing triangle.

Next: Increasing Triangle from 1

Move on to the increasing triangle starting from 1 in the Java number-pattern series.

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