Sequential Number Triangle Starting from 11 in Java

Beginner
⏱️ 6 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
Nested Loops

What You’ll Learn

How to print a sequential number triangle in Java where the first value is 11 and each row prints one more number than the previous.

You’ll use nested for loops and compute each value with 9 + i + j (row index + column index).

⭐ Pattern Output

For rows = 5, the pattern looks like this:

Output
11
12 13
13 14 15
14 15 16 17
15 16 17 18 19
1

Complete Java Program

The outer loop controls the row count. The inner loop prints i values, and each value is computed as 9 + i + j.

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

        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

Set the row count

int rows = 5; sets the triangle height.

Setup
2

Outer loop controls rows

for (int i = 1; i <= rows; i++) prints 1 number on row 1, 2 numbers on row 2, and so on.

Row control
3

Inner loop prints i values

for (int j = 1; j <= i; j++) runs exactly i times, so the row grows by one value each line.

Printing
4

Compute the value as 9 + i + j

When i=1 and j=1, the value is 11. As j increases, the numbers increase across the row.

Value logic
=

Sequential number triangle

Total numbers printed are 1+2+…+n = n(n+1)/2, so overall runtime grows like O(n²).

2

Variation — User Input Version

Let the user decide the number of rows at runtime using Scanner:

Java
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: ");
        int rows = sc.nextInt();

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

        sc.close();
    }
}

💡 Tips for Enhancement

Try These

  • Remove the trailing space by printing a space only when j < i
  • Change the start value by replacing 9 with a different constant
  • Right-align the triangle by printing leading spaces before each row
  • Use StringBuilder when you want custom separators or alignment
  • Convert it into an alphabet triangle by mapping numbers to letters

Avoid

  • Hard-coding 5 everywhere instead of using rows
  • Forgetting the newline (System.out.println()) after each row
  • Mixing row and column indices (keep i for rows, j for columns)
  • Closing System.in too early if you need more input later in the same run

Key Takeaways

1

Row i prints exactly i numbers.

2

The value formula 9 + i + j makes the first value 11.

3

Total printed values are n(n+1)/2, so work grows like O(n²).

4

This pattern is a good exercise for separating row control and value computation.

❓ Frequently Asked Questions

Because the first value on each row is computed with 9 + i + 1. When i increases by 1, the row start increases by 1 as well (11, 12, 13, 14, ...).
Yes. Print a space only between values: if j < i print " " after the number; otherwise skip it.
Replace 9 with a new constant. If you want the first value to be start, use (start - 2) + i + j.
O(n²) for n rows because the number of printed values is \(1+2+\dots+n\).

Explore More Java Number Patterns!

Once you’re comfortable with formulas like base + i + j, you can design many custom sequences.

All Number Patterns →
Did you know?

Many number patterns are just nested loops plus a value formula. Swapping 9 + i + j with another expression (like i*i + j) creates a completely different pattern.

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