ICSE Class 10 · Computer Applications (Java) · Pattern programs 2027

Pattern programs for ICSE, built from the loop rule instead of memorised.

Pattern programs in ICSE Class 10 Java are nested loops that print a shape of stars, numbers or letters. A student who learns twenty shapes by heart is stuck on the twenty-first. This page sorts twelve patterns by the rule behind them, rows, columns, spaces and characters, so any new pattern becomes three quick questions. Each one comes with its code and the output of a real Java 21 run, and in our live mini batch the same patterns are planned on paper before they go into BlueJ.

Live online · twelve patterns with real output · four loop rules · star, number and letter triangles · first class free

Start here

Courses where pattern programs are taught

The ICSE Java course in which the mini batch practises these patterns, the Class 11 and 12 Computer Science course where nested loops return in ISC programs, and Python for Teens for a student who wants to print the same shapes in a second language.

Ans. The short version

Pattern programs for ICSE Class 10 are Java programs that print a shape, such as a star triangle, a number pyramid or a letter triangle, using nested for loops. The outer loop runs once per row; the inner loop decides how many items that row holds; an optional first inner loop prints leading spaces; and the print statement decides which character appears. Answer three questions for any pattern: how many rows, how many items in row i, and what is printed at row i, column j. Modern Age Coders teaches pattern programs live in a Tuesday and Wednesday mini batch in India, or one to one at the family's time.

Q1. How do you write any pattern program in Java?

Nested loop patterns in Java for ICSE: the four loop rules

Every pattern is a grid printed one row at a time, so every pattern program is an outer loop for the rows with one or two inner loops inside. What changes from shape to shape is only the limit of the inner loop, whether spaces come first, and what gets printed.

RuleThe question it answersWhere it lives in the codeTypical form
RowsHow many lines does the shape have?The outer loop, ending with System.out.println()for (i = 1; i <= n; i++)
ColumnsHow many items does row i hold?The limit of the inner loop, written in terms of ij <= i, j <= n - i + 1, j <= 2 * i - 1
SpacesDoes row i start further to the right?A separate inner loop placed before the itemsfor (s = 1; s <= n - i; s++)
CharactersWhat is printed at row i, column j?The argument of System.out.print"*", j, i, (i + j) % 2, (char) ('A' + j - 1)

The three questions, in order

  1. Count the rows. That number is the outer loop's limit, usually n.
  2. Write down the item count for rows 1, 2 and 3. If it goes 1, 2, 3 the limit is i; if it goes 5, 4, 3 it is n - i + 1; if it goes 1, 3, 5 it is 2 * i - 1. If the left edge moves, count the spaces the same way.
  3. Look at one column. If the same column shows the same value on every row, print j. If a whole row repeats one value, print i. If nothing repeats, find the formula in i and j, or a test that picks the edge.

The full-mark answer is the same shape every time: Scanner input for n, the nested loops, a println() after each row and a variable description table. Here is the pyramid, written that way.

Pyramid.javaall four rules at once
import java.util.Scanner;
class Pyramid {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter the number of rows: ");
        int n = sc.nextInt();
        for (int i = 1; i <= n; i++) {              // rows
            for (int s = 1; s <= n - i; s++)        // spaces
                System.out.print(" ");
            for (int j = 1; j <= 2 * i - 1; j++)    // stars
                System.out.print("*");
            System.out.println();                   // end of the row
        }
    }
}

Row i has n - i spaces and 2i - 1 stars. Check row 1 and row n by hand before writing anything else: 4 spaces and 1 star, then 0 spaces and 9 stars.

VariableTypePurpose
nintnumber of rows, read from the user
iintcurrent row, 1 to n
sintcounts the leading spaces in row i
jintcounts the stars in row i
scScannerreads input from the keyboard
Sample runJava 21
Enter the number of rows: 5
    *
   ***
  *****
 *******
*********

Print a single space for each gap, not " ", or the slope doubles and the shape tilts.

Q2. How do you make a triangle grow or shrink?

Triangle pattern ICSE: changing only the inner loop limit

A left-aligned triangle needs no spaces at all. Rows and characters stay fixed while the inner loop's limit decides the shape: j <= i grows, j <= n - i + 1 shrinks.

PatternItems in rows 1, 2, 3Inner limitPrinted
Star triangle1, 2, 3j <= i"* "
Shrinking count5, 4, 3j <= n - i + 1j
Row repeat1, 2, 3j <= ii
RuleColumns.javathree triangles, three limits
class RuleColumns {
    static void starTriangle(int n) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= i; j++)
                System.out.print("* ");
            System.out.println();
        }
    }
    static void shrinkingCount(int n) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n - i + 1; j++)
                System.out.print(j + " ");
            System.out.println();
        }
    }
    static void rowRepeat(int n) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= i; j++)
                System.out.print(i + " ");
            System.out.println();
        }
    }
    public static void main(String args[]) {
        starTriangle(5);
        System.out.println("--");
        shrinkingCount(5);
        System.out.println("--");
        rowRepeat(5);
    }
}
OutputJava 21
*
* *
* * *
* * * *
* * * * *
--
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
--
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5

starTriangle and rowRepeat share the same loops and differ in one word: the star becomes i. That is the characters rule at work, and the reason to learn rules rather than shapes.

The most common slips with these three

Q3. How do you push a pattern to the right?

Star pattern program ICSE: right-aligned triangles, pyramids and the diamond

Add a spaces loop before the items. When row i has n - i spaces, row 1 starts furthest right and row n touches the margin, which turns a left triangle into a right-aligned one and, with 2i - 1 items, into the pyramid above.

RuleSpaces.javaspaces first, then items
class RuleSpaces {
    static void rightAligned(int n) {
        for (int i = 1; i <= n; i++) {
            for (int s = 1; s <= n - i; s++)
                System.out.print(" ");
            for (int j = 1; j <= i; j++)
                System.out.print("#");
            System.out.println();
        }
    }
    static void diamond(int n) {
        for (int i = 1; i <= n; i++) {              // top half, rows 1 to n
            for (int s = 1; s <= n - i; s++)
                System.out.print(" ");
            for (int j = 1; j <= 2 * i - 1; j++)
                System.out.print("*");
            System.out.println();
        }
        for (int i = n - 1; i >= 1; i--) {          // bottom half, rows n-1 down to 1
            for (int s = 1; s <= n - i; s++)
                System.out.print(" ");
            for (int j = 1; j <= 2 * i - 1; j++)
                System.out.print("*");
            System.out.println();
        }
    }
    public static void main(String args[]) {
        rightAligned(5);
        System.out.println("--");
        diamond(4);
    }
}
OutputJava 21
    #
   ##
  ###
 ####
#####
--
   *
  ***
 *****
*******
 *****
  ***
   *

The bottom half of the diamond is the same loop body as the top half, with the outer loop running backwards from n - 1. Starting it at n would print the widest row twice.

How many spaces? A quick table for row i of n rows

ShapeSpaces before row iItems in row iItem printed
Right-aligned trianglen - ii"#" with no space after it
Pyramid (solid)n - i2 * i - 1"*" with no space after it
Pyramid (spaced stars)n - ii"* ", the trailing space does the widening
Inverted pyramidi - 12 * (n - i) + 1"*"
Diamondpyramid of n rows, then inverted pyramid of n - 1 rowsas each half"*"

Spaces are where most pattern answers go wrong under exam pressure, so in the class every student draws the grid on squared paper first and writes the space count beside each row. The same habit of counting each pass is drilled on loop programs in Java for ICSE Class 10.

Q4. How do number, letter and 0 1 patterns work?

Number pattern Java Class 10: letters, 0 and 1, palindromes and hollow shapes

Once the rows, limits and spaces are right, the remaining work is the value printed at position (i, j). It can be a formula, a char made from a number, two loops that climb and then fall, or an if-else that picks the border.

PatternWhat is printed at (i, j)Why it works
0 1 triangle(i + j) % 2i + j changes parity at each step along a row and each step down a column
Letter triangle(char) ('A' + j - 1)'A' is 65; adding j - 1 and casting back gives A, B, C
Palindrome pyramidj from 1 up to i, then j from i - 1 down to 1Two inner loops: one climbs, one falls, so each row reads the same both ways
Hollow square"* " when i or j is 1 or n, else two spacesOnly the border passes the test; the gap must be as wide as a star plus its space
Word trianglew.substring(0, i)Row i shows the first i letters, so one loop is enough
RuleChars.javathe value at row i, column j
class RuleChars {
    static void binaryTriangle(int n) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= i; j++)
                System.out.print((i + j) % 2 + " ");
            System.out.println();
        }
    }
    static void letterTriangle(int n) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= i; j++)
                System.out.print((char) ('A' + j - 1) + " ");
            System.out.println();
        }
    }
    static void palinPyramid(int n) {
        for (int i = 1; i <= n; i++) {
            for (int s = 1; s <= n - i; s++)
                System.out.print(" ");
            for (int j = 1; j <= i; j++)        // climb: 1 to i
                System.out.print(j);
            for (int j = i - 1; j >= 1; j--)    // descend: i-1 to 1
                System.out.print(j);
            System.out.println();
        }
    }
    static void hollowSquare(int n) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                if (i == 1 || i == n || j == 1 || j == n)
                    System.out.print("* ");
                else
                    System.out.print("  ");
            }
            System.out.println();
        }
    }
    static void wordTriangle(String w) {
        for (int i = 1; i <= w.length(); i++)
            System.out.println(w.substring(0, i));
    }
    public static void main(String args[]) {
        binaryTriangle(5);
        System.out.println("--");
        letterTriangle(5);
        System.out.println("--");
        palinPyramid(4);
        System.out.println("--");
        hollowSquare(5);
        System.out.println("--");
        wordTriangle("BLUEJ");
    }
}
OutputJava 21
0
1 0
0 1 0
1 0 1 0
0 1 0 1 0
--
A
A B
A B C
A B C D
A B C D E
--
   1
  121
 12321
1234321
--
* * * * *
*       *
*       *
*       *
* * * * *
--
B
BL
BLU
BLUE
BLUEJ

Without the cast, 'A' + j - 1 is an int and the letter triangle prints 65, 66, 67. The cast must wrap the whole sum, which is why it sits outside the brackets.

Turn one pattern into another: practice changes

Each change below touches one rule only. Make it in BlueJ, predict the output first, then run it.

  1. In binaryTriangle, print (i + j + 1) % 2. The triangle now starts with 1 instead of 0.
  2. In letterTriangle, print (char) ('A' + i - 1). Every row repeats one letter: A, B B, C C C.
  3. In palinPyramid, remove the spaces loop. The rows become a left-aligned stack of palindromes.
  4. In hollowSquare, add || i == j to the test. A diagonal now crosses the square.
  5. In wordTriangle, print w.substring(w.length() - i). The word now builds from its last letter: J, EJ, UEJ.

Single letters printed with charAt instead of substring belong to the string family on ICSE Class 10 string programs, and tracing what a pattern prints without running it is practised on ICSE Computer Applications output questions.

Q5. Where do patterns appear in the ICSE paper?

Pattern programs in the ICSE 2027 paper, and how they are marked

Patterns appear in two places: as a full Section B program, and very often as one part of a method overloading question, where one version of the method prints a pattern and the others do something else. They also turn up in Section A as short trace questions.

Inside an overloading question

A recent pattern in board papers has been one method name with two or three parameter lists, one of which prints a number or symbol pattern. The pattern part is often the quickest marks in the question if the loop rules are second nature.

As a menu choice

A switch menu may offer a pattern as option 1 and a series as option 2. The pattern code goes inside its case, followed by break, and the default case handles a wrong choice.

As a trace in Section A

A short nested loop is shown and the student writes what it prints. The same rules work backwards: read the limits to find the item count per row.

What earns the marks

Correct loops and limits, a println at the end of each row, sensible variable names, comments on what each loop does and the variable description table. A shape that is off by one row usually loses part of the logic marks.

Check two rows by hand

Before moving on, trace row 1 and row n on the margin. Most wrong patterns are wrong at one end, and two quick traces catch both kinds of off-by-one.

Keep it to for loops

A pattern can be printed with while loops, but for loops show the counter, the limit and the step on one line, which makes the logic easy for the examiner to follow.

Overloading answers with a pattern inside are worked on user-defined methods and overloading for ICSE Class 10, and how often the pattern-in-overloading question came up in recent years is mapped on ICSE Computer Applications previous year papers, solved.

Q6. How are patterns taught in the live class?

From squared paper to BlueJ: a pattern lesson in the mini batch

Students see a new shape, plan it with the three questions, write it by hand and only then type it. The plan is the skill; typing is the check.

  1. A fresh shape on the shared screen

    At the Tuesday 5:30 PM IST class the teacher shows a pattern nobody has seen before, often a small variation of one on this page.

  2. Rows, limits, spaces and value, written as a plan

    Each student writes the four answers in a box before any code: the outer limit, the inner limit in terms of i, the space count and the value printed.

  3. Hand-written program, timed

    The program is written on paper against a clock, with a variable description table, as it would be in the paper.

  4. Run in BlueJ, fixed in front of the group

    The best and the most instructive wrong answers are typed and run. A tilted pyramid or a missing row is traced back to the one limit that caused it.

  5. Patterns inside full mock papers

    From December, patterns appear inside overloading and menu questions in complete two-hour mock papers, marked the way the board marks.

The other program families taught the same way are listed on ICSE Class 10 Java programs for practice; the next two to learn after patterns are series programs in Java and menu driven programs with switch case.

Batch or personalised: you choose

Practise patterns in the mini batch, or one to one

Both formats use the four loop rules, the planning box and the BlueJ check. Families in India can choose the fixed evening mini batch or a private slot; ICSE students living abroad are taught one to one. Billing is monthly and there is no admission fee.

Option 1 · Fixed batch timings

Mini batch, Tuesday 5:30 PM and Wednesday 8 PM

₹2,999

per month, two live classes a week

  • Tuesday 5:30 PM and Wednesday 8:00 PM IST, live
  • Up to six ICSE Class 10 students per batch
  • A new pattern planned on paper most weeks
  • Wrong shapes run and fixed while the group watches
  • Patterns revisited inside overloading and menu questions
Book a free demo in this batch

Option 2 · Choose your own timing

Personalised one to one

₹4,999

per month, one private class a week, at a time set with you

  • A time chosen by the family, in India or abroad
  • Extra time on whichever rule your child finds hard, often spaces
  • Shapes chosen to match the school's own worksheets
  • Harder patterns added once the basic triangles are secure
  • Same teachers, same 2027 syllabus, same BlueJ checks
Ask for a personalised plan

A student who freezes at any pattern that is not in the textbook usually needs a few one to one sessions on the three questions, and then the shapes stop being a problem. A student who wants all of Section B practised week by week, with patterns as one family among several, fits the twice-weekly batch. Fees are shown in your own currency.

Studying outside India?

Pattern program practice for ICSE students abroad

ICSE schools outside India set the same Computer Applications paper, so the same nested loop patterns turn up in their Section B. Overseas, the lessons run one to one at an early evening hour in the student's own time zone.

Where you liveTime differenceUsual class window, local timeFormat
India (IST)
every Indian city
ISTTue 5:30 PM, Wed 8:00 PMMini batch or 1-on-1
United Arab Emirates
Dubai, Sharjah
1 h 30 min behind India3:00 PM to 9:00 PMPersonalised 1-on-1
Indonesia and Thailand
West Java, Bangkok area
1 h 30 min ahead of India3:30 PM to 9:00 PMPersonalised 1-on-1
Singapore
Singapore
2 h 30 min ahead of India3:30 PM to 9:00 PMPersonalised 1-on-1

The slot is fixed after the free demo and can move around school tests. Families overseas can read more on ICSE Computer Applications classes in the Gulf and abroad.

What families say

Rated 4.9 across 547 Google reviews

Real reviews from real families. We neither write nor commission them.

★★★★★

"The one step solution for my son. Modern Age Coders make learning coding so simple that kids love it. The teachers explain complex concepts clearly with practical exercises and interactive content."

Ria Mukherjee

Parent

★★★★★

"Modern Age Coders has been a game-changer for me. I struggled to grasp IT concepts and coding before joining, but their classes transformed everything. I can now confidently write complex programs with ease."

Samriddha Mondal

Student

★★★★★

"One of the most wonderful education centres out there. Education is not limited to school syllabus but focuses on skill development."

Vansh Agarwal

Student

★★★★★

"My child Dhairya is really enjoying the Modern Age Coders classes. This is his first online class and he eagerly looks forward to it. I can already see his improvement, and the teachers are very cooperative."

Sonam Oswal

Parent of Dhairya

★★★★★

"Modern Age Coders have wonderful teachers who teach in a clear, easy and practical way. The teacher boosts students' confidence and inspires them to learn without hesitation."

Sonu Goyal

Parent

★★★★★

"I highly recommend this computer coding class! The teachers are incredibly knowledgeable and passionate about coding."

Ritu Kedia

Parent

The rest of the Class 10 series

More pages for Class 10 board students

Every page in the ICSE Class 10 Computer Applications series, grouped by what you need: classes, each chapter, Section B programs, question practice, notes and revision, and the exam itself.

CBSE Class 10 AI (417): The Mon and Wed 9 PM AI batch CBSE AI 417 syllabus explained CBSE AI important questions Sample paper and mock tests

Questions about pattern programs

What students ask about ICSE pattern programs

How do I solve any pattern program in Java?

Answer three questions before coding. How many rows are there? That is the outer loop. How many items are in row i? That is the inner loop limit, written using i. What is printed at row i, column j? That is the print statement. If the shape is pushed to the right, add a spaces loop before the items. Then trace row 1 and the last row by hand.

Are pattern programs important for ICSE Class 10?

Yes. They test nested loops, which are part of the 2027 Computer Applications syllabus, and they appear as Section B programs, as one part of method overloading questions and as Section A trace questions. A student who knows the loop rules can usually collect these marks quickly.

What is the difference between print and println in pattern programs?

print leaves the cursor on the same line, so the items of one row sit side by side. println moves to a new line. In a pattern, print goes inside the inner loop and a single println goes after the inner loop, once per row. Putting println inside the inner loop prints every item on its own line.

How do you print a star pyramid in Java?

Use an outer loop for i from 1 to n. Inside it, print n - i spaces, then 2 * i - 1 stars with no space between them, then call println. For n = 5 the first row has four spaces and one star, and the last row has nine stars and no spaces.

How do you print a letter pattern such as A, AB, ABC in Java?

Print (char) ('A' + j - 1) inside the inner loop, where j runs from 1 to i. Adding a number to a char gives an int, so the cast is needed to turn the code back into a letter. Without it the program prints 65, 66 and 67.

How do you print a 0 and 1 triangle pattern in Java?

Print (i + j) % 2 at row i, column j. The sum i + j changes between odd and even at every step, so the digits alternate along each row and each column. Use (i + j + 1) % 2 instead if the first row must start with 1.

How do you print a hollow square or hollow triangle?

Loop over every position in the grid and use an if-else. Print the symbol when the position is on the border (first row, last row, first column or last column) and print blanks otherwise. The blank must be as wide as the symbol plus any space printed after it.

Which loop is best for pattern programs?

The for loop, because the start, the limit and the step of each counter sit on one line, and a pattern is a fixed number of rows and items. While and do-while loops can print patterns too, but they make the limits harder to see and to mark.

Is recursion used for patterns in ICSE 2027?

No. Recursion is not part of the ICSE Computer Applications syllabus for 2027. Every pattern the paper can ask is printed with nested for loops, sometimes inside a method that takes n, a character or a word as a parameter.

Do you teach pattern programs in live classes?

Yes. In the ICSE mini batch a new pattern is planned on paper, written against the clock, then run and fixed in BlueJ on a shared screen. Students who need more time on nested loops can take personalised one to one classes at a time the family chooses.

Start

Try a free live pattern programs class

In the free demo your child meets a pattern they have not seen before, plans it with the mentor using rows, limits, spaces and the printed value, writes the code and runs it in BlueJ. You then hear honestly whether nested loops are already secure, and whether the mini batch or one to one will help more.

Looking at the whole subject first? See ICSE Computer Applications important questions or the ICSE Class 10 Java classes.

WhatsApp us · +91 91233 66161 · connect@modernagecoders.com

Every class is live video. The form requests a callback and reserves nothing.

We call within a few hours. No card, no enrolment fee.

Want it sooner? Book a priority demo

A full live class of about 45 to 60 minutes at a slot you pick, with a written skill report and learning roadmap on WhatsApp afterwards. The fee is adjusted against your first month if you enrol.

Book a priority demo

Keep exploring Modern Age Coders

By class and age

Learn more

Free resources

From the blog

Start here