Sequential Number Triangle Starting from 11 in Java

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:
11
12 13
13 14 15
14 15 16 17
15 16 17 18 19Complete Java Program
The outer loop controls the row count. The inner loop prints i values, and each value is computed as 9 + i + j.
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
Set the row count
int rows = 5; sets the triangle height.
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.
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.
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.
Sequential number triangle
Total numbers printed are 1+2+…+n = n(n+1)/2, so overall runtime grows like O(n²).
Variation — User Input Version
Let the user decide the number of rows at runtime using Scanner:
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
9with a different constant - Right-align the triangle by printing leading spaces before each row
- Use
StringBuilderwhen 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
ifor rows,jfor columns) - Closing
System.intoo early if you need more input later in the same run
Key Takeaways
Row i prints exactly i numbers.
The value formula 9 + i + j makes the first value 11.
Total printed values are n(n+1)/2, so work grows like O(n²).
This pattern is a good exercise for separating row control and value computation.
❓ Frequently Asked Questions
9 + i + 1. When i increases by 1, the row start increases by 1 as well (11, 12, 13, 14, ...).j < i print " " after the number; otherwise skip it.9 with a new constant. If you want the first value to be start, use (start - 2) + i + j.Explore More Java Number Patterns!
Once you’re comfortable with formulas like base + i + j, you can design many custom sequences.
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.
12 people found this page helpful
