-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPatterns.java
More file actions
108 lines (97 loc) · 3.33 KB
/
Copy pathPatterns.java
File metadata and controls
108 lines (97 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import java.util.Scanner;
public class Patterns {
// Function to print Star L shaped Pattern
public void Pattern_Star_L(int r) {
int no_of_rows = r;
for (int i = 1; i <= no_of_rows; ++i) {
for (int j = 1; j <= i; ++j) {
System.out.print("* ");
}
System.out.println();
}
}
// Function to print Number L shaped pattern
public void Pattern_Number_L(int r) {
int no_of_rows = r;
for (int i = 1; i <= no_of_rows; ++i) {
for (int j = 1; j <= i; ++j) {
System.out.print(j + " ");
}
System.out.println();
}
}
// Function to print Star Pyramid Pattern
public void Pattern_Star_Pyramid(int r) {
int no_of_rows = r;
int space = no_of_rows - 1;
for (int j = 1; j <= no_of_rows; j++) {
for (int i = 1; i <= space; i++) {
System.out.print(" ");
}
space--;
for (int i = 1; i <= 2 * j - 1; i++) {
System.out.print("*");
}
System.out.println("");
}
space = 1;
for (int j = 1; j <= no_of_rows - 1; j++) {
for (int i = 1; i <= space; i++) {
System.out.print(" ");
}
space++;
for (int i = 1; i <= 2 * (no_of_rows - j) - 1; i++) {
System.out.print("*");
}
System.out.println("");
}
}
// Function to print Number Pyramid Pattern
public void Number_Pyramid_Pattern(int r) {
int no_of_rows = r;
int space = no_of_rows - 1;
for (int i = 1; i <= no_of_rows; i++) {
int n = 8;
for (int j = 1; j <= n - i; j++) {
System.out.print(" ");
}
for (int k = i; k >= 1; k--) {
System.out.print(k);
}
for (int l = 2; l <= i; l++) {
System.out.print(l);
}
System.out.println();
}
for (int i = space; i >= 1; i--) {
int n = 10;
for (int j = 0; j <= n - i; j++) {
System.out.print(" ");
}
for (int k = i; k >= 1; k--) {
System.out.print(k);
}
for (int l = 2; l <= i; l++) {
System.out.print(l);
}
System.out.println();
}
}
// Main driver function
public static void main(String[] args) {
Patterns patterns = new Patterns();
Scanner sc = new Scanner(System.in);
System.out.println("Enter no of rows for star L shaped pattern:");
int rows_for_star_L = sc.nextInt();
patterns.Pattern_Star_L(rows_for_star_L);
System.out.println("\nEnter no of rows for number L shaped pattern:");
int rows_for_number_L = sc.nextInt();
patterns.Pattern_Number_L(rows_for_number_L);
System.out.println("\nEnter no of rows for star shaped pyramid pattern:");
int rows_for_star_Pyramid = sc.nextInt();
patterns.Pattern_Star_Pyramid(rows_for_star_Pyramid);
System.out.println("\nEnter no of rows for number shaped pyramid pattern:");
int rows_for_Number_Pyramid = sc.nextInt();
patterns.Number_Pyramid_Pattern(rows_for_Number_Pyramid);
}
}