44
55
66
7- *****
8- * *
9- * *
10- *****
11-
12-
7+ * * * * *
8+ * *
9+ * *
10+ * * * * *
11+ */
1312public class Jpatturn {
1413 public static void hollow_rectangle (int rows , int col ){
1514 for (int i =1 ; i <=rows ; i ++){
@@ -25,32 +24,179 @@ public static void hollow_rectangle(int rows, int col){
2524 System .out .println ();
2625 }
2726 }
28-
29- public static void main(String args[]){
30- hollow_rectangle(7,7);
31- }
32- }
33-
27+ /*
3428 INVERTED ROTATED HALF PYRAMID
3529 *
3630 * *
3731 * * *
3832 * * * *
3933 * * * * *
40- public class Jpatturn{
41- public static void main(String args[]){
42- inverted_rotated_half_Pyramid(5);
43- }
44-
34+ */
4535 public static void inverted_rotated_half_Pyramid (int n ){
4636 for (int i =1 ; i <=n ; i ++){
4737 for (int j =1 ; j <=n -i ; j ++){
48- Snystem .out.print(" ");
38+ System .out .print (" " );
4939 }
5040 for (int j =1 ; j <=i ; j ++){
5141 System .out .print (" * " );
5242 }
5343 System .out .println ();
5444 }
5545 }
56- }*/
46+ 47+ /*
48+ 1 2 3 4 5
49+ 1 2 3 4
50+ 1 2 3
51+ 1 2
52+ 1
53+ */
54+ public static void inverted_half_num_pyramid (int n ){
55+ for (int i =1 ; i <=n ; i ++){
56+ for (int j =1 ; j <=n -i +1 ; j ++){
57+ System .out .print (j +" " );
58+ }
59+ System .out .println ();
60+ }
61+ 62+ }
63+ /* FLOYD'S TRIANGLE
64+ 1
65+ 2 3
66+ 4 5 6
67+ 7 8 9 10
68+ 11 12 13 14 15
69+ */
70+ 71+ public static void floydsTriangle (int n ){
72+ int counter = 1 ;
73+ for (int i =1 ; i <=n ; i ++){
74+ for (int j =1 ; j <=i ; j ++){
75+ System .out .print (counter +" " );
76+ counter ++;
77+ }
78+ System .out .println ();
79+ }
80+ }
81+ 82+ /* 0-1 Triangle
83+ 1
84+ 0 1
85+ 1 0 1
86+ 0 1 0 1
87+ 1 0 1 0 1
88+ */
89+ public static void binaryTriangle (int n ){
90+ for (int i =1 ; i <=n ; i ++){
91+ for (int j =1 ; j <=i ; j ++){
92+ if ((i +j )%2 ==0 ){
93+ System .out .print ("1 " );
94+ }
95+ else {
96+ System .out .print ("0 " );
97+ }
98+ 99+ 100+ }
101+ System .out .println ();
102+ }
103+ }
104+ /* BUTTERFLY (n=4)
105+ * *
106+ * * * *
107+ * * * * * *
108+ * * * * * * * *
109+ * * * * * * * *
110+ * * * * * *
111+ * * * *
112+ * *
113+
114+ */
115+ 116+ public static void butterfly (int n ){
117+ // outter loop -> lines/rows
118+ for (int i =1 ; i <=n ; i ++){
119+ // innner loop -> star 1
120+ for (int j =1 ; j <=i ; j ++){
121+ System .out .print (" * " );
122+ }
123+ // inner loop2 -> space
124+ for (int j =1 ; j <=2 *(n -i ); j ++){
125+ System .out .print (" " );
126+ }
127+ // innner loop3 -> star 2
128+ for (int j =1 ; j <=i ; j ++){
129+ System .out .print (" * " );
130+ }
131+ // next line
132+ System .out .println ();
133+ }
134+ // mirror of above -> reverce loop
135+ for (int i =n ; i >=1 ; i --){
136+ for (int j =1 ; j <=i ; j ++){
137+ System .out .print (" * " );
138+ }
139+ for (int j =1 ; j <=2 *(n -i ); j ++){
140+ System .out .print (" " );
141+ }
142+ for (int j =1 ; j <=i ; j ++){
143+ System .out .print (" * " );
144+ }
145+ System .out .println ();
146+ }
147+ 148+ 149+ }
150+ /* Solid Rhombus
151+ * * * * *
152+ * * * * *
153+ * * * * *
154+ * * * * *
155+ * * * * *
156+ */
157+ public static void solid_rhombus (int n ){
158+ for (int i =1 ; i <=n ; i ++){
159+ for (int j =1 ; j <=n -i ; j ++){
160+ System .out .print (" " );
161+ }
162+ for (int j =1 ; j <=n ; j ++ ){
163+ System .out .print (" * " );
164+ }
165+ System .out .println ();
166+ }
167+ }
168+ /* Hollow Rhombus
169+ * * * * *
170+ * *
171+ * *
172+ * *
173+ * * * * *
174+ */
175+ public static void hollow_Rhombus (int n ){
176+ for (int i =1 ; i <=n ; i ++){
177+ for (int j =1 ; j <=n -i ; j ++){
178+ System .out .print (" " );
179+ }
180+ for (int j =1 ; j <=n ; j ++){
181+ if (i ==1 || i ==n || j ==1 || j ==n ){
182+ System .out .print (" * " );
183+ }
184+ else {
185+ System .out .print (" " );
186+ }
187+ }
188+ System .out .println ();
189+ }
190+ }
191+ public static void main (String args []){
192+ //hollow_rectangle(7,7);
193+ //inverted_rotated_half_Pyramid(5);
194+ //inverted_half_num_pyramid(5);
195+ //floydsTriangle(7);
196+ //binaryTriangle(5);
197+ //butterfly(5);
198+ //solid_rhombus(5);
199+ hollow_Rhombus (5 );
200+ }
201+ }
202+
0 commit comments