-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp.java
More file actions
102 lines (83 loc) · 2.74 KB
/
Copy pathp.java
File metadata and controls
102 lines (83 loc) · 2.74 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
// public class p {
// public static void main(String[] args){
// int i, j,n=5;
// for (i = n-1; i > 0; i--) {
// // inner loop to print spaces.
// for (j = n - i; j > 1; j--) {
// System.out.print(" ");
// }
// // inner loop to print stars.
// for (j = 0; j <= i; j++) {
// System.out.print("* ");
// }
// // printing new line for each row
// System.out.println();
// }
// // outer loop to handle rows
// // for (i = 0; i < n; i++) {
// // // inner loop to print spaces.
// // for (j = n - i; j > 1; j--) {
// // System.out.print(" ");
// // }
// // // inner loop to print stars.
// // for (j = 0; j <= i; j++) {
// // System.out.print("* ");
// // }
// // // printing new line for each row
// // System.out.println();
// // }
// }
// // public static void java(String str){
// // int sum = a+b;
// // System.out.println(sum);
// // for(int i=3;i>=0;i--){
// // System.out.print(str.charAt(i));
// // }
// // int rev = str
// //}
// // public static void main(String args[]){
// // for(int i=0;i<=5;i++){
// // System.out.print(i);
// // for(int j=i;j<=5;j++){
// // System.out.println(j);
// // }
// // }
// // System.out.println( java(1,2));
// // int arr[] = {1,2,3,4};
// // String str = "abcd";
// // java(str);
// // }
// }
public class p {
public static void main(String[] args) {
printPattern();
}
public static void printPattern() {
int totalRows = 7; // Total number of rows in the pattern
// Upper part of the pattern
for (int i = 0; i < totalRows / 2; i++) {
// Print leading spaces
for (int j = 0; j < i; j++) {
System.out.print(" ");
}
// Print asterisks
for (int j = 0; j < totalRows - 2 * i; j++) {
System.out.print("*");
}
System.out.println(); // Move to the next line
}
System.out.println(" *");
// Lower part of the pattern
for (int i = 1; i <= totalRows / 2; i++) {
// Print leading spaces
for (int j = 0; j < totalRows / 2 - i; j++) {
System.out.print(" ");
}
// Print asterisks
for (int j = 0; j < 2 * i + 1; j++) {
System.out.print("*");
}
System.out.println(); // Move to the next line
}
}
}