Skip to content

Commit c4542ee

Browse files
Simple Question
Duration 2 day 15/09/2023 - 16/09/2023
1 parent 23392e7 commit c4542ee

File tree

6 files changed

+219
-0
lines changed

6 files changed

+219
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
public class HollowRectangelPattern {
2+
public static void main(String[] args) {
3+
int n = 5;
4+
5+
for (int i=1; i<=n; i++) {
6+
for (int j=1; j<= n+1; j++) {
7+
if ((i == 1) || (i == n) || (j == 1) || (j == (n + 1))) System.out.print("*");
8+
else System.out.print(" ");
9+
}
10+
System.out.println();
11+
}
12+
}
13+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
public class InvertedRotatedHalfPyramid {
2+
public static void main(String[] args) {
3+
int n = 5;
4+
5+
for (int i=1; i<=n; i++) {
6+
for (int j=1; j<=n-i; j++) {
7+
System.out.print(" ");
8+
}
9+
for (int k=1; k<=i; k++) {
10+
System.out.print("*");
11+
}
12+
System.out.println();
13+
}
14+
}
15+
}

Pattern (Part 1)/MultiplePattern.java

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
public class MultiplePattern {
2+
3+
public static void invertedHalf(int n) {
4+
for (int i=1; i<=n; i++) {
5+
int num = 1;
6+
for (int j=1; j<=n-i+1; j++) {
7+
System.out.print(num);
8+
num++;
9+
}
10+
System.out.println();
11+
}
12+
}
13+
14+
public static void floydTriangle(int n) {
15+
int num = 1;
16+
for (int i=1; i<=n; i++) {
17+
for (int j=1; j<=i; j++) {
18+
System.out.print(num);
19+
num++;
20+
}
21+
System.out.println();
22+
}
23+
}
24+
25+
public static void rhombus(int n) {
26+
for (int i=1; i<=n; i++) {
27+
for (int j=1; j<=n-i; j++) {
28+
System.out.print(" ");
29+
}
30+
for (int k=1; k<=n; k++) {
31+
System.out.print("*");
32+
}
33+
System.out.println();
34+
}
35+
}
36+
37+
public static void hollowRhombus(int n) {
38+
for (int i=1; i<=n; i++) {
39+
for (int j=1; j<=n-i; j++) {
40+
System.out.print(" ");
41+
}
42+
for (int k=1; k<=n; k++) {
43+
if ((i==1) || (i==n) || (k==1) || (k==(n-1))) System.out.print("*");
44+
else System.out.print(" ");
45+
}
46+
System.out.println();
47+
}
48+
}
49+
50+
public static void butterfuly(int n) {
51+
String str = "*";
52+
for (int i=1; i<=n; i++) {
53+
System.out.print(str);
54+
for (int k=1; k<=(n-i)*2; k++) {
55+
System.out.print(" ");
56+
}
57+
System.out.print(str);
58+
str += "*";
59+
System.out.println();
60+
}
61+
for (int i=n; i>=1; i--) {
62+
for (int j=1; j<=i; j++) {
63+
System.out.print("*");
64+
}
65+
for (int k=1; k<=(n-i)*2; k++) {
66+
System.out.print(" ");
67+
}
68+
for (int l=1; l<=i; l++) {
69+
System.out.print("*");
70+
}
71+
System.out.println();
72+
}
73+
}
74+
75+
public static void diamond(int n) {
76+
for (int i=1; i<=n; i++) {
77+
for (int j=1; j<=n-i; j++) {
78+
System.out.print(" ");
79+
}
80+
for (int k=1; k<=((2*i)-1); k++) {
81+
System.out.print("*");
82+
}
83+
System.out.println();
84+
}
85+
for (int i=n-1; i>=1; i--) {
86+
for (int j=1; j<=n-i; j++) {
87+
System.out.print(" ");
88+
}
89+
for (int k=1; k<=((2*i)-1); k++) {
90+
System.out.print("*");
91+
}
92+
System.out.println();
93+
}
94+
}
95+
96+
public static void numberPyramid(int n) {
97+
for (int i=1; i<=n; i++) {
98+
int num = 1;
99+
for (int j=1; j<=n-i; j++) {
100+
System.out.print(" ");
101+
}
102+
for (int k=1; k<=i; k++) {
103+
System.out.print(i+" ");
104+
}
105+
System.out.println();
106+
}
107+
}
108+
109+
public static void palindromic(int n) {
110+
for (int i=1; i<=n; i++) {
111+
for (int j=1; j<=n-i; j++) {
112+
System.out.print(" ");
113+
}
114+
for (int k=i; k>=1; k--) {
115+
System.out.print(k);
116+
}
117+
for (int l=2; l<=i; l++) {
118+
System.out.print(l);
119+
}
120+
System.out.println();
121+
}
122+
}
123+
124+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
public class PrintCharacterPattern {
2+
public static void highComplexity(int n) {
3+
char ch = 'A';
4+
for (int i=1; i<=n; i++) {
5+
for (int j=1; j<=i; j++) {
6+
System.out.print(ch);
7+
ch++;
8+
}
9+
System.out.println();
10+
}
11+
}
12+
13+
public static void lowComplexity (int n, char ch) {
14+
String str = "A";
15+
for (int i=1; i<=n; i++) {
16+
System.out.println(str);
17+
ch++;
18+
String temp = String.valueOf(ch);
19+
str += temp;
20+
}
21+
}
22+
23+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Time Complexity O(n)
2+
// Used Variable(3), DataType Conversion (1), Loop(1)
3+
/*
4+
* Output :
5+
* 1
6+
* 12
7+
* 123
8+
* 1234
9+
*/
10+
public class PrintHalfPyramid {
11+
public static void main(String[] args) {
12+
int n = 4;
13+
String num = "1";
14+
int temp = 1;
15+
for (int i=1; i<=n; i++) {
16+
System.out.println(num);
17+
temp ++;
18+
String temperory = String.valueOf(temp);
19+
num += temperory;
20+
}
21+
}
22+
}

Pattern (Part 1)/StarPattern.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// try to done at O(n) Complexity
2+
/*
3+
* Output :
4+
* *
5+
* **
6+
* ***
7+
* ****
8+
*/
9+
public class StarPattern {
10+
public static void printPattern(int n){
11+
// Write your code here.
12+
String str = "*";
13+
for (int i=1; i<=n; i++) {
14+
System.out.println(str);
15+
str += "*";
16+
}
17+
}
18+
19+
public static void main(String[] args) {
20+
printPattern(4);
21+
}
22+
}

0 commit comments

Comments
 (0)