File tree Expand file tree Collapse file tree 10 files changed +425
-0
lines changed
src/patterns_Programming/core/day_15 Expand file tree Collapse file tree 10 files changed +425
-0
lines changed Original file line number Diff line number Diff line change 1+ package patterns_Programming .core .day_15 ;
2+ /*
3+ Diamond Pattern (Size = 5)
4+ *
5+ ***
6+ *****
7+ *******
8+ *********
9+ *******
10+ *****
11+ ***
12+ *
13+ */
14+ import java .util .*;
15+ public class DiamondPattern
16+ {
17+ public static void diamondPattern (int row ,int col )
18+ {
19+ for (int i = 1 ;i <=row -1 ;i ++) // row -1 because we need to print the middle row exactly once
20+ {
21+ for (int space = 1 ;space <= row -i ;space ++)
22+ {
23+ System .out .print (" " );
24+ }
25+ for (int j = 1 ; j <=i *2 -1 ;j ++)
26+ {
27+ System .out .print ("*" );
28+ }
29+ System .out .println ();
30+ }
31+
32+ for (int i = row ;i >=1 ;i --)
33+ {
34+ for (int space = 1 ;space <= row - i ;space ++)
35+ {
36+ System .out .print (" " );
37+ }
38+ for (int j = 1 ;j <=i *2 -1 ;j ++)
39+ {
40+ System .out .print ("*" );
41+ }
42+ System .out .println ();
43+ }
44+ }
45+ public static void main (String [] args )
46+ {
47+ Scanner sc = new Scanner (System .in );
48+ System .out .println ("Enter the number of rows :" );
49+ int row = sc .nextInt ();
50+ System .out .println ("Enter the number of column :" );
51+ int col = sc .nextInt ();
52+ diamondPattern (row ,col );
53+ sc .close ();
54+ }
55+ }
56+
Original file line number Diff line number Diff line change 1+ package patterns_Programming .core .day_15 ;
2+ /*
3+ Full pyramid using `*`
4+ *
5+ * *
6+ * * *
7+ * * * *
8+
9+ */
10+ import java .util .*;
11+ public class FullPyramind
12+ {
13+ public static void fullPyramid (int row ,int col )
14+ {
15+ for (int i = 1 ;i <=row ;i ++)
16+ {
17+ for (int j = col ;j >=i ;j --)
18+ {
19+ System .out .print (" " );
20+ }
21+ for (int k = 1 ;k <=i ;k ++)
22+ {
23+ System .out .print (" *" );
24+ }
25+ System .out .println ();
26+ }
27+ }
28+ public static void main (String [] args )
29+ {
30+ Scanner sc = new Scanner (System .in );
31+ System .out .println ("Enter number of rows :" );
32+ int row = sc .nextInt ();
33+ System .out .println ("Enter number of columns :" );
34+ int col = sc .nextInt ();
35+ fullPyramid (row , col );
36+ sc .close ();
37+ }
38+ }
Original file line number Diff line number Diff line change 1+ package patterns_Programming .core .day_15 ;
2+
3+ import java .util .Scanner ;
4+
5+ /*
6+ Hollow Diamond Pattern
7+ *
8+ * *
9+ * *
10+ * *
11+ * *
12+ * *
13+ * *
14+ * *
15+ *
16+
17+ */
18+ public class HollowDiamond
19+ {
20+ public static void hollowPattern (int row )
21+ {
22+ for (int i = 1 ; i <= row ; i ++)
23+ {
24+ for (int space = 1 ; space <= row - i ; space ++)
25+ {
26+ System .out .print (" " );
27+ }
28+ for (int j = 1 ; j <= 2 * i - 1 ; j ++)
29+ {
30+ if (j == 1 || j == 2 * i - 1 )
31+ System .out .print ("*" );
32+ else
33+ System .out .print (" " );
34+ }
35+ System .out .println ();
36+ }
37+
38+ for (int i = row - 1 ; i >= 1 ; i --)
39+ {
40+ for (int space = 1 ; space <= row - i ; space ++)
41+ {
42+ System .out .print (" " );
43+ }
44+
45+ for (int j = 1 ; j <= 2 * i - 1 ; j ++)
46+ {
47+ if (j == 1 || j == 2 * i - 1 )
48+ System .out .print ("*" );
49+ else
50+ System .out .print (" " );
51+ }
52+ System .out .println ();
53+ }
54+ }
55+
56+ public static void main (String [] args )
57+ {
58+ Scanner sc = new Scanner (System .in );
59+ System .out .println ("Enter the number of rows :" );
60+ int row = sc .nextInt ();
61+
62+ hollowPattern (row );
63+ sc .close ();
64+ }
65+ }
Original file line number Diff line number Diff line change 1+ package patterns_Programming .core .day_15 ;
2+ /*
3+
4+ Hollow square of `*` (5x5)
5+ *****
6+ * *
7+ * *
8+ * *
9+ *****
10+
11+ */
12+ import java .util .*;
13+ public class HollowSquare
14+ {
15+ public static void hollowSquare (int row , int col )
16+ {
17+ for (int i = 1 ;i <=row ;i ++)
18+ {
19+ for (int j = 1 ;j <=col ;j ++)
20+ {
21+ if (i == 1 ||i ==row ||j ==1 ||j ==col )
22+ {
23+ System .out .print ("*" );
24+ }
25+ else
26+ {
27+ System .out .print (" " );
28+ }
29+ }
30+ System .out .println ();
31+ }
32+ }
33+ public static void main (String [] args )
34+ {
35+ Scanner sc = new Scanner (System .in );
36+ System .out .println ("Enter the number of rows :" );
37+ int row = sc .nextInt ();
38+ System .out .println ("Enter the number of columns :" );
39+ int col = sc .nextInt ();
40+ hollowSquare (row , col );
41+ sc .close ();
42+ }
43+ }
Original file line number Diff line number Diff line change 1+ package patterns_Programming .core .day_15 ;
2+
3+ import java .util .Scanner ;
4+
5+ /*
6+ Hollow Triangle Pattern
7+ *
8+ **
9+ * *
10+ * *
11+ *****
12+ */
13+ public class HollowTriangle
14+ {
15+ public static void hollow (int row )
16+ {
17+ for (int i = 1 ;i <=row ;i ++)
18+ {
19+ for (int j = 1 ;j <=i ;j ++)
20+ {
21+ if (i ==j ||i ==row ||j ==1 )
22+ System .out .print ("*" );
23+ else
24+ System .out .print (" " );
25+ }
26+ System .out .println ();
27+ }
28+ }
29+ public static void main (String [] args ) {
30+ Scanner sc = new Scanner (System .in );
31+ System .out .println ("Enter the number of rows : " );
32+ int row = sc .nextInt ();
33+ hollow (row );
34+ sc .close ();
35+
36+ }
37+ }
Original file line number Diff line number Diff line change 1+ package patterns_Programming .core .day_15 ;
2+ /*
3+ Inverted full pyramid using `*`
4+ *********
5+ *******
6+ *****
7+ ***
8+ *
9+ */
10+ import java .util .*;
11+ public class InvertedFullPyramid
12+ {
13+ public static void invertedFullPyramid (int row ,int col )
14+ {
15+ for (int i = row ;i >=1 ;i --)
16+ {
17+ for (int space = 1 ;space <=row -i ;space ++)
18+ {
19+ System .out .print (" " );
20+ }
21+ for (int j = 1 ;j <=i *2 -1 ;j ++)
22+ {
23+ System .out .print ("*" );
24+ }
25+ System .out .println ();
26+ }
27+ }
28+ public static void main (String [] args ) {
29+ Scanner sc = new Scanner (System .in );
30+ System .out .println ("Enter number of rows :" );
31+ int row = sc .nextInt ();
32+ System .out .println ("Enter number of columns :" );
33+ int col = sc .nextInt ();
34+ invertedFullPyramid (row , col );
35+ sc .close ();
36+ }
37+ }
Original file line number Diff line number Diff line change 1+ package patterns_Programming .core .day_15 ;
2+ /*
3+
4+ Inverted right-angled triangle using `*`
5+ *****
6+ ****
7+ ***
8+ **
9+ *
10+
11+ */
12+ import java .util .*;
13+ public class InvertedRightAngledTriangle
14+ {
15+ public static void invertedRightAngleTriangle (int row ,int col )
16+ {
17+ for (int i = 1 ;i <=row ;i ++)
18+ {
19+ for (int j = col ;j >=i ;j --)
20+ {
21+ System .out .print ("*" );
22+ }
23+ System .out .println ();
24+ }
25+ }
26+ public static void main (String [] args ) {
27+ Scanner sc = new Scanner (System .in );
28+ System .out .println ("Enter number of rows :" );
29+ int row = sc .nextInt ();
30+ System .out .println ("Enter number of columns :" );
31+ int col = sc .nextInt ();
32+ invertedRightAngleTriangle (row , col );
33+ sc .close ();
34+ }
35+ }
Original file line number Diff line number Diff line change 1+ package patterns_Programming .core .day_15 ;
2+ /*
3+ Right-angled triangle using `*`
4+ *
5+ **
6+ ***
7+ ****
8+ *****
9+ */
10+ import java .util .*;
11+ public class RightAngledTriangle
12+ {
13+ public static void rightAngledTriangle (int row ,int col )
14+ {
15+ for (int i = 1 ;i <=row ;i ++)
16+ {
17+ for (int j = 1 ;j <=i ;j ++)
18+ {
19+ System .out .print ("*" );
20+ }
21+ System .out .println ();
22+ }
23+ }
24+ public static void main (String [] args ) {
25+ Scanner sc = new Scanner (System .in );
26+ System .out .println ("Enter number of rows :" );
27+ int row = sc .nextInt ();
28+ System .out .println ("Enter number of columns :" );
29+ int col = sc .nextInt ();
30+ rightAngledTriangle (row , col );
31+ sc .close ();
32+ }
33+
34+ }
Original file line number Diff line number Diff line change 1+ package patterns_Programming .core .day_15 ;
2+ /*
3+ Solid square of `*` (5x5)
4+
5+ *****
6+ *****
7+ *****
8+ *****
9+ *****
10+
11+ */
12+ import java .util .*;
13+ public class SolidSquare
14+ {
15+ public static void solidSquare (int row ,int col )
16+ {
17+ for (int i = 1 ; i <=row ;i ++)
18+ {
19+ for (int j = 1 ;j <=col ;j ++)
20+ {
21+ System .out .print ("*" );
22+ }
23+ System .out .println ();
24+ }
25+ }
26+ public static void main (String [] args )
27+ {
28+ Scanner sc = new Scanner (System .in );
29+ System .out .println ("Enter number of rows : " );
30+ int row = sc .nextInt ();
31+ System .out .println ("Enter number of columns :" );
32+ int col = sc .nextInt ();
33+ solidSquare (row , col );
34+ sc .close ();
35+
36+ }
37+
38+ }
You can’t perform that action at this time.
0 commit comments