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

Pattern Problems Java

The document presents 25 pattern problems with Java solutions, including examples like a square pattern, right-angle triangle, and a number crown pattern. Each problem is accompanied by input specifications, expected output, and corresponding Java code to generate the patterns. This serves as a resource for practicing pattern generation in Java programming.

Uploaded by

rajnishr0001
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)
4 views2 pages

Pattern Problems Java

The document presents 25 pattern problems with Java solutions, including examples like a square pattern, right-angle triangle, and a number crown pattern. Each problem is accompanied by input specifications, expected output, and corresponding Java code to generate the patterns. This serves as a resource for practicing pattern generation in Java programming.

Uploaded by

rajnishr0001
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

25 Pattern Problems with Java Solutions

1. Square Pattern
Input: n = 4
Output:
****
****
****
****
Code:
public class Solution {
public static void squarePattern(int n) {
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
[Link]("*");
}
[Link]();
}
}
}

2. Right-Angle Triangle
Input: n = 4
Output:
*
**
***
****
Code:
public class Solution {
public static void rightTriangle(int n) {
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= i; j++) {
[Link]("*");
}
[Link]();
}
}
}

3. Number Crown Pattern


Input: n = 3
Output:
1 1
12 21
123321
Code:
public class Solution {
public static void numberCrown(int n) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
[Link](j + " ");
}
for (int s = 1; s <= 2 * (n - i); s++) {
[Link](" ");
}
for (int j = i; j >= 1; j--) {
[Link](j + " ");
}
[Link]();
}
}
}

You might also like