ICSE Class 9 Java Pattern Cheat Sheet (with Output)
1. Rectangle Pattern
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= cols; j++) {
System.out.print("* ");
}
System.out.println();
}
Sample Output:
* * * *
* * * *
* * * *
2. Left-Aligned Triangle (Straight)
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= i; j++) {
System.out.print("* ");
}
System.out.println();
}
Sample Output:
*
* *
* * *
* * * *
3. Left-Aligned Triangle (Upside Down)
for (int i = rows; i >= 1; i--) {
for (int j = 1; j <= i; j++) {
System.out.print("* ");
}
System.out.println();
}
Sample Output:
* * * *
* * *
* *
*
4. Right-Aligned Triangle (Straight)
for (int i = 1; i <= rows; i++) {
for (int space = 1; space <= rows - i; space++) {
System.out.print(" ");
}
for (int star = 1; star <= i; star++) {
System.out.print("* ");
}
ICSE Class 9 Java Pattern Cheat Sheet (with Output)
System.out.println();
}
Sample Output:
*
* *
* * *
* * * *
5. Right-Aligned Triangle (Upside Down)
for (int i = rows; i >= 1; i--) {
for (int space = 1; space <= rows - i; space++) {
System.out.print(" ");
}
for (int star = 1; star <= i; star++) {
System.out.print("* ");
}
System.out.println();
}
Sample Output:
* * * *
* * *
* *
*