Powers of 11 Number Pattern in Java

Beginner
⏱️ 8 min read
📚 Updated: Aug 2026
🎯 3 Code Examples
🚀 Live Preview
Single Loop × 11

What You’ll Learn

The powers-of-11 pattern prints 1, 11, 121, 1331, 14641 — each line is the previous value multiplied by 11. This tutorial covers the single-loop logic, overflow-safe BigInteger variant, live preview, worked Java examples, edge cases, and complexity.

Shape Rule

× 11 each row

Start res = 1; each iteration prints res, then res = res * 11.

Single Loop

i = 1..rows

for (i = 1; i <= rows; i++) — one line printed per iteration.

Overflow Safe

BigInteger

Use long for small demos; switch to BigInteger when rows grow — Example 2.

Pascal Link

Early rows

First few lines match Pascal’s triangle rows written without spaces.

Live Preview

3–12 rows

Pick a row count and draw the powers of 11 pattern instantly in the browser.

O(n)

Complexity

One loop iteration per row — linear time; extra memory stays O(1).

Introduction

A powers-of-11 number pattern prints 1, then 11, then 121, up to 14641 for five rows. Each line equals the previous value times 11.

In Java you initialize long res = 1, loop rows times, call println(res), then update with res = res * 11.

Why it matters?

It is a compact single-loop exercise that also connects to Pascal’s triangle and overflow awareness.

Key Highlights

Start at 1

res = 1 produces the first line.

Multiply by 11

res *= 11 after each print.

One Loop

No nested loops — one iteration, one line.

Series Foundation

Follow Program 47 concentric diamond; continue to Program 49 multiplication triangle.

In short: res = 1, loop rows times, println(res), then res *= 11.

📝 Problem & Approach

Given rows = 5, print five lines: 1, 11, 121, 1331, 14641.

Java
// rows = 5 (conceptual output)
// 1
// 11
// 121
// 1331
// 14641

Inputs & Outputs

ItemTypeDescription
rowsintHow many lines to print (typically ≥ 1).
reslong / BigIntegerRunning value — starts at 1, multiplied by 11 each step.
Printed outputtextOne number per line — rows total lines.

Minimal workflow

Pseudocode
res = 1
for i from 1 to rows:
    print res
    res = res * 11

Approach comparison

ApproachIdeaBest for
long multiplyres = res * 11 after each printSmall row counts (≤ ~9 safely)
BigInteger + Scannerres.multiply(11)Large row counts without overflow
Single-line outputprint(res + " ")Compact one-row display — Example 3

⚡ Quick Reference

GoalPattern
Initializelong res = 1;
Loop rowsfor (i = 1; i <= rows; i++)
Print lineSystem.out.println(res);
Updateres = res * 11;
BigInteger updateres = res.multiply(BigInteger.valueOf(11));
Program 47 contrastConcentric diamond uses nested loops; this pattern uses one loop and multiply-by-11

📋 Print vs Update vs Combined

Three phases of each loop iteration — print the current value, then prepare the next line.

Initialize
res = 1

First line is always 1 before any multiplication.

Print
println(res)

Output the current value on its own line.

Update
res *= 11

Multiply by 11 to get the next row’s value.

Learning tip
trace i=3

Dry-run iteration 3: res=121 → prints 121, then res=1331.

Context

When This Pattern Shows Up

Reach for this pattern when teaching single-loop series, overflow awareness, and Pascal’s-triangle connections.

  1. First lab exercise

    Classic follow-up after concentric diamonds and single-loop series patterns.

  2. Series & overflow lesson

    Introduce long vs BigInteger when values grow quickly.

  3. Console I/O practice

    Combine loops with Scanner for a flexible row count.

  4. Gateway to variants

    Compare with Program 47 (concentric diamond), then continue to Program 49 (multiplication triangle).

  5. Not a UI layout tool

    This is a console teaching pattern — not how you build modern app screens.

Key benefit: one small program that locks in loop variables, running totals, and O(n) thinking.

🔮 Live Preview

Choose a row count and draw the powers of 11 pattern in the browser.

Try 3, 5, or 8 rows (up to 12).

Live result
Press "Draw pattern".

Examples Gallery

Three complete Java programs — fixed rows with long, BigInteger + Scanner, and a single-line output variant. Click View Output to reveal sample console results.

📚 Getting Started

Print five lines with a single loop and multiply-by-11 updates.

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;
        }
    }
}

How It Works

Iteration 1 prints 1, then res becomes 11. Iteration 2 prints 11, then res becomes 121 — and so on.

📈 Practical Variant

Use BigInteger so larger row counts do not overflow.

Example 2 — BigInteger + Scanner

Read rows with Scanner and multiply with BigInteger.

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();

        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();
    }
}

How It Works

Same loop structure as Example 1; BigInteger grows without the overflow limits of long.

⚡ Readability Variant

Print all values on one line separated by spaces.

Example 3 — Single-Line Output

Use print with a trailing space, then one final println.

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();
    }
}

How It Works

Same multiply-by-11 logic; only the output format changes — one horizontal line instead of five vertical lines.

🧠 How the Algorithm Prints Rows

1

Set up

System.out is built in; use Scanner when reading input. Set rows and initialize res = 1.

Setup
2

Loop rows

for (i = 1; i <= rows; i++) — one iteration per output line.

Loop
3

Print then update

println(res) then res = res * 11 prepares the next line.

Update
4

Result

After 5 iterations: 1, 11, 121, 1331, 14641 — linear O(n) work.

Done
=

Powers of 11 number pattern complete

Total lines printed = rowsO(n) time, O(1) extra memory.

🔎 Worked Walkthrough — iteration i = 3

Trace the third loop iteration to see print-then-multiply in action.

Stepres beforeAction
i = 11print 1 → res = 11
i = 211print 11 → res = 121
i = 3121print 121 → res = 1331

Line 3 output: 121 — five rows produce five values ending at 14641.

Use Cases

Where this tiny pattern (and its loop structure) shows up beyond the homework prompt.

1. Teaching Running Totals

Classic intro to accumulator variables updated each iteration.

Example: use BigInteger for large row counts — see Example 2.

2. Pascal’s Triangle Link

Early rows match Pascal without spaces — great math connection.

Example: compare row 5 (14641) with Pascal row coefficients.

3. Console Formatting Drills

Practice println vs print for multi-line vs single-line output.

Example: put System.out.print(res + " ") for one-line output — Example 3.

4. Overflow Awareness

Watch int and long limits as values grow by 11 each step.

Example: print 10+ rows and observe when long wraps.

5. Complexity Intuition

One loop iteration per row makes O(n) concrete for beginners.

Example: count lines for rows=5 → five values from 1 up to 14641.

6. Input Validation Labs

Pair the pattern with Scanner and positive-row checks.

Example: reject rows <= 0 and re-prompt.

Pro Tip: when an interviewer asks for patterns, explain the print-then-update order first — then write the loop. The story matters as much as the code.

Advantages

Why this pattern earns a permanent spot in beginner Java courses.

  1. 1. Instant Visual Feedback

    Wrong update order (multiply before print) skips the first line 1.

  2. 2. Minimal Concepts

    Only loops and console output — no arrays or math libraries.

  3. 3. Easy to Extend

    Change rows, switch to BigInteger, or print on one line with spaces.

  4. 4. O(1) Extra Memory

    Streaming output needs no storage beyond loop counters.

Pro Tip: learn the fixed-rows loop first; then try BigInteger input and the single-line variant in Example 3.

Usage Tips

Small habits that keep number-pattern code clean.

  1. 1. Name Variables Clearly

    Use rows for the loop bound and res for the running value.

  2. 2. Prefer Scanner

    Avoid crashes when the user types letters instead of a number.

  3. 3. Print Before Update

    Always println(res) before res *= 11 so the first line is 1.

  4. 4. Pick the Right Type

    Use long for demos; switch to BigInteger when rows grow.

  5. 5. Dry-Run One Small n

    Trace rows = 3 on paper before coding larger demos.

Pro Tip: if the first line is missing or wrong, check whether you multiply before printing.

Common Pitfalls

Mistakes that commonly break powers of 11 number patterns.

  1. 1. Multiplying Before Printing

    Updating res first skips the initial value 1 on line one.

    → Print res, then multiply: res = res * 11.

  2. 2. Using int for Many Rows

    int overflows after a few multiplications by 11 — values become negative or wrong.

    → Use long for small demos or BigInteger for larger row counts.

  3. 3. Starting res at 0 or 11

    Wrong initial value shifts the entire sequence.

    → Initialize res = 1 (or BigInteger.ONE).

  4. 4. Forgetting Final Newline (Single-Line Variant)

    Using only print may leave the cursor on the same line as the last value.

    → Add System.out.println() after the loop — Example 3.

  5. 5. Unchecked Scanner Input

    Letters or empty input throw InputMismatchException.

    → Use sc.hasNextInt() before sc.nextInt().

  6. 6. Hard-coding 5 Everywhere

    Using literal 5 in loop bounds instead of variable rows breaks dynamic input.

    → Use one rows variable for the loop bound.

Edge Cases

Check these inputs before calling the solution done.

rows = 1

Single line

Output is one line: 1.

rows = 0

Empty pattern

Loop never runs — print nothing or show a message.

Negative

rows < 0

Treat as invalid; re-prompt instead of silent empty output.

Large n

Many rows

long overflows around row 10; use BigInteger for more lines.

Bad input

Non-numeric Scanner input

Unchecked Scanner leaves rows unset — call sc.hasNextInt() first.

Compact

Single-line form

Use print(res + " ") for one horizontal line — see Example 3.

🎯 Practice Problems

Try these variations to lock in the pattern.

1. Change rows

  • Try rows = 3, 6, or 8
  • Watch when long overflows

2. BigInteger stretch

  • Print 15+ rows with Example 2
  • Compare digit lengths row by row

3. Different multiplier

  • Replace 11 with 12 or 10
  • Observe the new sequence

4. Next in series

  • Continue with Program 49 multiplication triangle
  • Connect to nested-loop patterns

Notes

  • Line count. Total lines printed = rows (e.g. 5 lines for rows=5).
  • print stays on the line; println advances — mix them carefully.
  • Validate rows > 0 for interactive programs; rows = 1 prints one value.
  • Print before multiply — otherwise the first line is not 1.

Quick Takeaway: set res=1, loop rows times, println(res), then res *= 11.

⏱️ Time and Space Complexity

ProgramTimeExtra space
Fixed rows (Example 1)O(n)O(1)
BigInteger + Scanner (Example 2)O(n) loop; multiply cost grows with digitsO(1)
Single-line output (Example 3)O(n)O(1)
Wrap Up

🎉 Conclusion

The powers of 11 pattern combines a single loop with repeated multiplication — a natural step after concentric number diamonds. Master the fixed-rows version first, then try BigInteger input and the single-line variant in Example 3.

Practice the three examples above, then continue to Program 49 for the multiplication number triangle pattern.

Print before update — keep res = 1 as the starting value.

💡 Best Practices

✅ Do

  • Explain res=1, print, and res*=11 before coding
  • Use println(res) then res *= 11 each iteration
  • Validate rows ≥ 1 for interactive programs
  • Check Scanner return value before using rows
  • State O(n) time when asked about complexity

❌ Don’t

  • Multiply before printing (skips the first line 1)
  • Use int for many rows (overflows quickly)
  • Hard-code 5 instead of variable rows
  • Ignore bad console input in user-facing demos
  • Skip the rows = 1 edge case

Key Takeaways

Knowledge Unlocked

Five things to remember about this powers of 11 number pattern

Print the pattern the beginner-friendly way.

5
Core concepts
02

Initialize

res = 1

Code
03

Multiply ×11

res *= 11

Logic
n 04

One line/row

n iterations

I/O
O 05

Complexity

O(n)

Analysis

❓ 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.

Continue to Program 49

Move on to the multiplication number triangle pattern in the Java number-pattern series.

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