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.
Approach
How to Solve It
Grow i from 1 to rows; for each row print j = 1..i values of base + i + j.
Method
Idea
Best for
Fixed base 9
Print (9 + i + j) + " " in nested loops
Learning, interviews, exams
Custom base
Replace 9 with a baseVal from input
When 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
Goal
Pattern
Walk rows
for (int i = 1; i <= rows; i++)
Print i values
for (int j = 1; j <= i; j++)
Compute value
System.out.print((9 + i + j) + " ");
End the row
System.out.println();
Custom base
System.out.print((baseVal + i + j) + " ");
Printing Numbers vs Starting a New Line
API
Effect
Use for
System.out.print
Stays on the same line
Each number plus trailing space
System.out.println
Ends the current line
After the inner loop finishes
Print values without a newline, then end the row once.
Try it
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 resultrows = 5 · 15 values
11
12 13
13 14 15
14 15 16 17
15 16 17 18 19
Trace
Worked Walkthrough — rows = 5
Trace i, the inner range j = 1..i, and 9 + i + j for each cell.
i
Values of 9 + i + j
Printed row
1
11
11
2
12, 13
12 13
3
13, 14, 15
13 14 15
4
14 … 17
14 15 16 17
5
15 … 19
15 16 17 18 19
Total values = 1 + 2 + … + 5 = 15 — the triangular number n(n+1)/2.
Code
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();
}
}
}
Output
11
12 13
13 14 15
14 15 16 17
15 16 17 18 19
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();
}
}
Output (when user enters rows 3, base 9)
Enter rows: 3
Enter base: 9
11
12 13
13 14 15
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();
}
}
}
Output
11
12 13
13 14 15
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.
Analysis
Time and Space Complexity
Program
Time
Extra space
Increasing from 11 (Examples 1–3)
O(n²)
O(1)
Total values = n(n+1)/2 — still quadratic. Only loop counters are stored.
Remember
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.