The ICSE polygon() overloading task pairs three void methods with distinct parameter lists to render console patterns via nested for loops: polygon(int n, char ch) prints an n Γ n square of ch, polygon(int x, int y) prints an x-row by y-column rectangle of @, and zero-argument polygon() prints a growing * triangle. Outer loops advance rows with println(), while inner loops repeat symbols on the same line via print().
- 1. Zero-Argument vs. Parameterized Overload Design
- 2. Controlling Rows and Columns with Nested Loops
- 3. Dry-Running Loop Counters for ICSE Section B
- 4. PolygonPattern.java β Overloaded polygon() Nested Loop Patterns
- 5. CISCE Variable Description Table (VDT) & Dry Run
- 6. Common Mistakes & Top Scorer Tips
- 7. Interactive Concept Check Quiz
- 8. Frequently Asked Questions
1. Zero-Argument vs. Parameterized Overload Design
The polygon() problem shows how a single class can combine a zero-argument overload with two-argument overloads cleanly. Calling obj.polygon() triggers the parameterless triangle builder, obj.polygon(n, ch) draws a custom-symbol square, and obj.polygon(x, y) draws an @-filled rectangle. Notice that both two-argument methods accept two values yet remain unambiguous because their second parameter types differ (char versus int). Keep all three return types as void since each method renders multi-line console shapes directly rather than returning a single scalar value.
- Zero-argument polygon() demonstrates overloading with arity 0 alongside arity 2.
- polygon(int, char) and polygon(int, int) share 2 parameters but differ in the second type.
- All three methods use void because console drawing has no numerical return result.
2. Controlling Rows and Columns with Nested Loops
Every two-dimensional pattern relies on two nested for loops: an outer loop i counting rows from 1 to the height, and an inner loop j printing characters across each row. For the square and rectangle, the inner limit stays constant (n or y), producing uniform rows. For the right-angled triangle inside polygon(), the inner loop stops at i (j <= i), adding one extra * on every new line. Always place System.out.print() inside the inner loop and System.out.println() outside it so characters stay on the same row.
- Outer loop variable i controls the total number of horizontal lines printed.
- Inner loop variable j controls how many characters appear on the current line.
- Empty System.out.println() advances the cursor only after an entire row completes.
3. Dry-Running Loop Counters for ICSE Section B
Examiners award full Section B marks when your dry run proves you understand how loop bounds behave on boundary values. For instance, calling obj.polygon(3, '#') runs outer i for 1, 2, 3 and inner j three times per row, printing a 3 Γ 3 grid of #. Calling obj.polygon(2, 4) limits rows to 2 and columns to 4, catching swapped x and y variables immediately. Documenting n, ch, x, y, i, j clearly in the Variable Description Table makes your logic effortless to verify.
- Test non-square dimensions such as x = 2, y = 4 so row/column swaps show up immediately.
- Show row-by-row counter progression (i = 1 -> *, i = 2 -> **, i = 3 -> ***) during exam dry runs.
- List loop indices i and j explicitly in your Variable Description Table.
4. PolygonPattern.java β Overloaded polygon() Nested Loop Patterns
import java.util.*;
public class PolygonPattern {
public void polygon(int n, char ch) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
System.out.print(ch);
}
System.out.println();
}
}
public void polygon(int x, int y) {
for (int i = 1; i <= x; i++) {
for (int j = 1; j <= y; j++) {
System.out.print("@");
}
System.out.println();
}
}
public void polygon() {
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= i; j++) {
System.out.print("*");
}
System.out.println();
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
PolygonPattern pp = new PolygonPattern();
System.out.print("Enter side and character for square: ");
int n = sc.nextInt();
char ch = sc.next().charAt(0);
pp.polygon(n, ch);
System.out.print("Enter rows and columns for rectangle: ");
int x = sc.nextInt();
int y = sc.nextInt();
pp.polygon(x, y);
System.out.println("Right-angled triangle pattern:");
pp.polygon();
sc.close();
}
}
Verified Console / Dry-Run Output:
Enter side and character for square: 3 #
###
###
###
Enter rows and columns for rectangle: 2 4
@@@@
@@@@
Right-angled triangle pattern:
*
**
***
5. CISCE Variable Description Table (VDT) & Dry Run
| Variable | Data Type | Exam Purpose & Sample Value |
|---|---|---|
| n | int | Side length of the filled square (3) |
| ch | char | Fill character passed to polygon(int, char) ('#') |
| x, y | int | Row count and column count of the rectangle (2, 4) |
| i | int | Outer loop counter controlling row number (1..3) |
| j | int | Inner loop counter controlling symbols per row (1..4) |
| pp | PolygonPattern | Object reference used to invoke all polygon() methods |
Conquer Java Pattern Programs Live
Build confidence with nested loops, pattern dry runs, and ICSE overloaded polygon() questions in a 1-on-1 live BlueJ class.
6. Common Mistakes & Top Scorer Tips
- Avoid Mistake: Calling System.out.println(ch) inside the inner loop instead of System.out.print(ch), printing one vertical column.
- Avoid Mistake: Swapping row count x and column count y in polygon(int x, int y), flipping width and height.
- Avoid Mistake: Using j <= 3 instead of j <= i inside zero-argument polygon(), printing a 3x3 square instead of a triangle.
- Examiner / Mentor Tip: Draw a miniature 3-row output sketch next to your rough work before coding to confirm i and j limits.
- Examiner / Mentor Tip: Match exact symbols required by the question ('@' for rectangle, '*' for triangle, user char for square).
- Examiner / Mentor Tip: Never omit the empty System.out.println() after the inner loopβit is the #1 bug in ICSE pattern code.
7. Interactive Concept Check Quiz
Question: What pattern does pp.polygon(2, 4) print in the PolygonPattern class?
8. Frequently Asked Questions
Can Java confuse polygon(int, char) and polygon(int, int) at compile time?
Why did my polygon() pattern print a single vertical column instead of a grid?
How many rows should zero-argument polygon() print in ICSE exams?
Explore Related Lessons & Free Interactive Tools
- All 110 Guides in ICSE Java BlueJ Library
- ElectricBill Class Slab Calculation Program in Java (ICSE)
- RailwayTicket Class Program in ICSE Java (BlueJ)
- BookFair Class Program in Java for ICSE Class 10
- Interactive Tool: ICSE Class 10 Java BlueJ Output Quiz
- Interactive Tool: ICSE Variable Description Table (VDT) Auto-Formatter
