0% found this document useful (0 votes)
8 views2 pages

ICSE Class 9 Java Patterns With Output

This document provides a cheat sheet for ICSE Class 9 Java patterns, including code snippets and sample outputs for various shapes. Patterns include rectangles, left-aligned triangles (both straight and upside down), and right-aligned triangles (both straight and upside down). Each pattern is demonstrated with corresponding Java code and its output format.

Uploaded by

sas.sk1988
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

ICSE Class 9 Java Patterns With Output

This document provides a cheat sheet for ICSE Class 9 Java patterns, including code snippets and sample outputs for various shapes. Patterns include rectangles, left-aligned triangles (both straight and upside down), and right-aligned triangles (both straight and upside down). Each pattern is demonstrated with corresponding Java code and its output format.

Uploaded by

sas.sk1988
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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:
* * * *
* * *
* *
*

You might also like