A powers-of-11 pattern prints 1, 11, 121, 1331, 14641 — each line is the previous value multiplied by 11.
Remember
Rule: res = 1
for each row: print res; res = res * 11
1
11
121
1331
14641 ← rows = 5
Unlike Program 47 (nested concentric diamond), here one loop and one multiply build the whole pattern.
Approach
How to Solve It
Start at 1; each iteration prints the current value, then multiplies by 11.
Method
Idea
Best for
long loop
println(res) then res *= 11
Small demos (about 5–12 rows)
BigInteger
Same loop; multiply with BigInteger
Many rows without overflow
Pseudocode
Pseudocode
res = 1
for i from 1 to rows:
print res
res = res * 11
Cheat sheet
Goal
Pattern
Start
long res = 1;
Walk rows
for (int i = 1; i <= rows; i++)
Print line
System.out.println(res);
Next value
res = res * 11;
Safe growth
res = res.multiply(BigInteger.valueOf(11));
Printing Numbers vs Starting a New Line
API
Effect
Use for
System.out.println
Ends the line
One value per row (Examples 1–2)
System.out.print
Stays on the same line
Single-line display (Example 3)
Choose whether each value starts a new line.
Try it
Live Preview
Change the row count and the powers-of-11 sequence updates instantly.
Whole numbers from 3 to 12. Tap a chip or type a value — the preview redraws as you go.
Live resultrows = 5 · last = 14641
1
11
121
1331
14641
Trace
Worked Walkthrough — rows = 5
Trace res before and after each multiply-by-11 step.
i
Print
Then res *= 11
1
1
11
2
11
121
3
121
1331
4
1331
14641
5
14641
161051 (not printed)
Always print first, then multiply — otherwise the first line would skip 1.
Code
Java Programs
Three complete programs: fixed long rows, BigInteger + Scanner, and single-line output. Use View Output to reveal sample results.
Example 1 — Fixed rows = 5 (long)
Hard-coded size — print res, then multiply by 11 each iteration.
Java
public class PowersOf11Pattern {
public static void main(String[] args) {
int rows = 5;
long res = 1;
for (int i = 1; i <= rows; i++) {
System.out.println(res);
res = res * 11;
}
}
}
Output
1
11
121
1331
14641
How It Works
1. Start at 1.res holds the current line’s value.
2. Print then multiply.println(res) first; res *= 11 prepares the next line.
3. Repeat. After five iterations you have 1 … 14641.
Prefer long over int — int overflows after only a few ×11 steps.
Example 2 — BigInteger + Scanner
Read rows at runtime. Same loop with unlimited growth.
Java
import java.math.BigInteger;
import java.util.Scanner;
public class PowersOf11PatternInput {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number of rows: ");
int rows = sc.nextInt();
if (rows < 1) return;
BigInteger res = BigInteger.ONE;
BigInteger eleven = BigInteger.valueOf(11);
for (int i = 1; i <= rows; i++) {
System.out.println(res);
res = res.multiply(eleven);
}
sc.close();
}
}
Output (when user enters 5)
Enter the number of rows: 5
1
11
121
1331
14641
How It Works
1. Prompt and guard. Read rows; exit early if it is less than 1.
2. Same loop. Only the type of res changes — multiply with multiply(eleven).
3. Safer input tip. Prefer:
Safer input
if (!sc.hasNextInt()) {
System.out.println("Enter a positive integer.");
return;
}
int rows = sc.nextInt();
if (rows < 1) {
System.out.println("Enter a positive integer.");
return;
}
Example 3 — Single-Line Output
Same multiply-by-11 logic — values printed on one horizontal line.
Java
public class PowersOf11PatternInline {
public static void main(String[] args) {
int rows = 5;
long res = 1;
for (int i = 1; i <= rows; i++) {
System.out.print(res + " ");
res = res * 11;
}
System.out.println();
}
}
Output
1 11 121 1331 14641
How It Works
1. Same math. Still print then res *= 11.
2. Different layout.print(res + " ") keeps everything on one line.
3. Final break. One println() after the loop ends the line cleanly.
Edge Cases & Pitfalls
Check these before calling the solution done.
Multiply first
Missing 1
If you multiply before printing, the first line becomes 11 instead of 1. Always print, then multiply.
int overflow
Wrong negatives
int overflows after a few ×11 steps. Prefer long, or BigInteger for many rows.
Start at 0
All zeros
Starting res at 0 keeps every line at 0. Start at 1.
rows = 1
Single value
Output is just 1.
Pascal myth
Carries appear
Early rows look like Pascal digits glued together. Larger rows have carries — not pure digit concatenation.
Bad input
Use hasNextInt
nextInt() throws on letters — prefer hasNextInt() and require a positive integer.
Analysis
Time and Space Complexity
Program
Time
Extra space
long loop (Examples 1, 3)
O(n)
O(1)
BigInteger (Example 2)
O(n) iterations*
grows with digit length
*Each BigInteger multiply costs more as digits grow, but the loop still runs once per row.
Remember
Key Takeaways
Rule: start at 1; print, then res *= 11 each row.
Order matters: print before multiply so the first line is 1.
Type choice:long for small demos; BigInteger for many rows.
Complexity:O(n) iterations for n rows.
One line:res = 1; for each row, println(res) then res *= 11.
Frequently Asked Questions
Starting from 1, each step multiplies the previous value by 11: 1×11=11, 11×11=121, 121×11=1331, 1331×11=14641.
Yes for larger rows if you use int or long. Use BigInteger in Example 2 to print more lines safely.
Early results resemble Pascal rows written without spaces. For larger rows, digit carrying appears, so the trick no longer matches simple concatenation.
int overflows after a few multiplications by 11. long handles more rows before overflow — BigInteger handles any practical row count.
Yes. Use System.out.print(res + " ") instead of println — see Example 3.
O(n) loop iterations for n rows. BigInteger multiplication cost grows with digit length but the loop count stays linear.
Yes. Replace 11 with another integer to explore a different sequence — the loop structure stays the same.
Use sc.hasNextInt() before sc.nextInt() so bad input does not throw InputMismatchException.
🤔
Did you know?
Start with res = 1, print it, then multiply by 11 each row. The first five lines are 1, 11, 121, 1331, 14641 — early rows resemble Pascal’s triangle without spaces.