★★★★★
"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
ICSE Class 10 · Computer Applications (Java) · Pattern programs 2027
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
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.

The batch / ICSE CA
Class 9 and 10 Computer Applications in a mini batch, where a new pattern is planned and run most weeks until nested loops feel routine.
Open the course →
Next step / ISC
For students going on to ISC Computer Science, where nested loops drive matrices, sorting and longer programs.
Open the course →
Second language / Python
For the student who likes shapes and wants to see the same loop rules written in Python after the board exam.
Open the course →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?
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.
| Rule | The question it answers | Where it lives in the code | Typical form |
|---|---|---|---|
| Rows | How many lines does the shape have? | The outer loop, ending with System.out.println() | for (i = 1; i <= n; i++) |
| Columns | How many items does row i hold? | The limit of the inner loop, written in terms of i | j <= i, j <= n - i + 1, j <= 2 * i - 1 |
| Spaces | Does row i start further to the right? | A separate inner loop placed before the items | for (s = 1; s <= n - i; s++) |
| Characters | What is printed at row i, column j? | The argument of System.out.print | "*", j, i, (i + j) % 2, (char) ('A' + j - 1) |
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.
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.
| Variable | Type | Purpose |
|---|---|---|
| n | int | number of rows, read from the user |
| i | int | current row, 1 to n |
| s | int | counts the leading spaces in row i |
| j | int | counts the stars in row i |
| sc | Scanner | reads input from the keyboard |
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?
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.
| Pattern | Items in rows 1, 2, 3 | Inner limit | Printed |
|---|---|---|---|
| Star triangle | 1, 2, 3 | j <= i | "* " |
| Shrinking count | 5, 4, 3 | j <= n - i + 1 | j |
| Row repeat | 1, 2, 3 | j <= i | i |
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);
}
}
* * * * * * * * * * * * * * * -- 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.
Q3. How do you push a pattern to the right?
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.
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);
}
}
# ## ### #### ##### -- * *** ***** ******* ***** *** *
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.
| Shape | Spaces before row i | Items in row i | Item printed |
|---|---|---|---|
| Right-aligned triangle | n - i | i | "#" with no space after it |
| Pyramid (solid) | n - i | 2 * i - 1 | "*" with no space after it |
| Pyramid (spaced stars) | n - i | i | "* ", the trailing space does the widening |
| Inverted pyramid | i - 1 | 2 * (n - i) + 1 | "*" |
| Diamond | pyramid of n rows, then inverted pyramid of n - 1 rows | as 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?
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.
| Pattern | What is printed at (i, j) | Why it works |
|---|---|---|
| 0 1 triangle | (i + j) % 2 | i + 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 pyramid | j from 1 up to i, then j from i - 1 down to 1 | Two 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 spaces | Only the border passes the test; the gap must be as wide as a star plus its space |
| Word triangle | w.substring(0, i) | Row i shows the first i letters, so one loop is enough |
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");
}
}
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.
Each change below touches one rule only. Make it in BlueJ, predict the output first, then run it.
binaryTriangle, print (i + j + 1) % 2. The triangle now starts with 1 instead of 0.letterTriangle, print (char) ('A' + i - 1). Every row repeats one letter: A, B B, C C C.palinPyramid, remove the spaces loop. The rows become a left-aligned stack of palindromes.hollowSquare, add || i == j to the test. A diagonal now crosses the square.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?
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.
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.
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.
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.
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.
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.
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?
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.
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.
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.
The program is written on paper against a clock, with a variable description table, as it would be in the paper.
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.
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
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
₹2,999
per month, two live classes a week
Option 2 · Choose your own timing
₹4,999
per month, one private class a weektwo private classes a week, at a time set with you
Outside India: the ICSE Computer Applications course runs as personalised one to one, two private classes a week at a time set in your own time zone. The mini batch is taught for families in India.
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?
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 live | Time difference | Usual class window, local time | Format |
|---|---|---|---|
| India (IST) every Indian city | IST | Tue 5:30 PM, Wed 8:00 PM | Mini batch or 1-on-1 |
| United Arab Emirates Dubai, Sharjah | 1 h 30 min behind India | 3:00 PM to 9:00 PM | Personalised 1-on-1 |
| Indonesia and Thailand West Java, Bangkok area | 1 h 30 min ahead of India | 3:30 PM to 9:00 PM | Personalised 1-on-1 |
| Singapore Singapore | 2 h 30 min ahead of India | 3:30 PM to 9:00 PM | Personalised 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
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
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
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.
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.
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.
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.
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.
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.
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.
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.
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.
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
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.
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