forked from Midway91/HactoberFest2023
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StarPatternQuestion.java
87 lines (66 loc) · 2.03 KB
/
StarPatternQuestion.java
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
public class StarPatternQuestion {
public static void main(String[] args) {
pattern6_12345mirror(4);
pattern1_54321star(4);
pattern2_12345star(4);
pattern3_12345numeric(4);
pattern5_543212345numeric(4);
}
static void pattern6_12345mirror(int n){
for(int i=1;i<=n;i++)
{
for(int j=0;j<n-i;j++)
{
System.out.print(" ");
}
for(int j=0;j<i;j++)
{
System.out.print("*");
}
System.out.println();
}
}
static void pattern1_54321star(int n){
for(int i = 5 ; i>0 ; i--){
// System.out.println(" ");
for(int j=0;j<i;j++){
System.out.print(" * ");
}
System.out.println(" ");
}
}
static void pattern2_12345star(int n){
for(int i = 0 ; i<5 ; i++){
for(int j=0;j<i;j++){
System.out.print(" * ");
}
System.out.println(" ");
}
}
static void pattern3_12345numeric(int n){
for(int i = 1 ; i<=5 ; i++){
for(int j=1;j<=i;j++){
System.out.print(j+"\t");
}
System.out.println(" ");
}
}
static void pattern4_123454321star(int n){
for(int i=0;i<2*n;i++){
int k = i>n ? 2*n-i:i;
for(int j = 0;j<=k;j++){
System.out.print("* ");
}
System.out.println();
}
}
static void pattern5_543212345numeric(int n){
for(int i=2*n;i>0;i--){
int k = i>n ? i:2*n-i;
for(int j = 0;j<=k;j++){
System.out.print("* ");
}
System.out.println();
}
}
}