Java Powers of 11 Number Pattern

Beginner
6 min read
Updated: Sep 2026
3 programs
Live preview

What Is This Pattern?

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.

How to Solve It

Start at 1; each iteration prints the current value, then multiplies by 11.

MethodIdeaBest for
long loopprintln(res) then res *= 11Small demos (about 5–12 rows)
BigIntegerSame loop; multiply with BigIntegerMany rows without overflow

Pseudocode

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

Cheat sheet

GoalPattern
Startlong res = 1;
Walk rowsfor (int i = 1; i <= rows; i++)
Print lineSystem.out.println(res);
Next valueres = res * 11;
Safe growthres = res.multiply(BigInteger.valueOf(11));

Printing Numbers vs Starting a New Line

APIEffectUse for
System.out.printlnEnds the lineOne value per row (Examples 1–2)
System.out.printStays on the same lineSingle-line display (Example 3)

Choose whether each value starts a new line.

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 result rows = 5 · last = 14641
1
11
121
1331
14641

Worked Walkthrough — rows = 5

Trace res before and after each multiply-by-11 step.

iPrintThen res *= 11
1111
211121
31211331
4133114641
514641161051 (not printed)

Always print first, then multiply — otherwise the first line would skip 1.

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

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

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

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.

Time and Space Complexity

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

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.

Next: Multiplication Number Triangle

Move on to the multiplication number triangle 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