0% found this document useful (0 votes)
12 views4 pages

Java Pattern Programming Professional Notes

This document provides an overview of pattern programming in Java, focusing on the use of nested loops to create various patterns. It includes examples of increasing and decreasing star patterns, number patterns, Floyd's triangle, hollow squares, and pyramid patterns. Each pattern is accompanied by a code snippet demonstrating how to implement it in Java.

Uploaded by

Jyotirmoy Maiti
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)
12 views4 pages

Java Pattern Programming Professional Notes

This document provides an overview of pattern programming in Java, focusing on the use of nested loops to create various patterns. It includes examples of increasing and decreasing star patterns, number patterns, Floyd's triangle, hollow squares, and pyramid patterns. Each pattern is accompanied by a code snippet demonstrating how to implement it in Java.

Uploaded by

Jyotirmoy Maiti
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

JAVA PATTERN PROGRAMMING

Professional Notes

1. Introduction to Pattern Programming

Pattern programs in Java are mainly based on nested loops. The outer loop controls the number of
rows and the inner loop controls the number of columns.

Basic Structure:

for (int i = 1; i <= n; i++) { // Rows


for (int j = 1; j <= m; j++) { // Columns
// Print statement
}
[Link]();
}

2. Increasing Star Pattern

*
* *
* * *
* * * *
* * * * *

for (int i = 1; i <= 5; i++) {


for (int j = 1; j <= i; j++) {
[Link]("* ");
}
[Link]();
}
3. Decreasing Star Pattern

* * * * *
* * * *
* * *
* *
*

for (int i = 5; i >= 1; i--) {


for (int j = 1; j <= i; j++) {
[Link]("* ");
}
[Link]();
}

4. Number Increasing Pattern

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

for (int i = 1; i <= 5; i++) {


for (int j = 1; j <= i; j++) {
[Link](j + " ");
}
[Link]();
}
5. Floyd's Triangle

1
2 3
4 5 6
7 8 9 10
11 12 13 14 15

int number = 1;
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++) {
[Link](number + " ");
number++;
}
[Link]();
}

6. Hollow Square Pattern

* * * * *
* *
* *
* *
* * * * *

for (int i = 1; i <= 5; i++) {


for (int j = 1; j <= 5; j++) {
if (i == 1 || i == 5 || j == 1 || j == 5) {
[Link]("* ");
} else {
[Link](" ");
}
}
[Link]();
}
7. Pyramid Pattern

*
* *
* * *
* * * *
* * * * *

for (int i = 1; i <= 5; i++) {


for (int j = 1; j <= 5 - i; j++) {
[Link](" ");
}
for (int k = 1; k <= i; k++) {
[Link]("* ");
}
[Link]();
}

End of Notes

You might also like