File tree Expand file tree Collapse file tree 1 file changed +68
-0
lines changed Expand file tree Collapse file tree 1 file changed +68
-0
lines changed Original file line number Diff line number Diff line change 1+ package pattern_program ;
2+
3+ /*
4+ Write a program to print letter H exactly as shown below -
5+
6+ $$$$$##$$$$$
7+ ##
8+ ##
9+ ##
10+ ##
11+ ##
12+ ##
13+ ##
14+ ##
15+ ##
16+ $$$$$##$$$$$
17+ */
18+
19+
20+ import java .util .Scanner ;
21+
22+ public class Letter_I {
23+
24+ // main logic
25+ public static void printI (int patternHeight )
26+ {
27+
28+ for (int i = 0 ; i < patternHeight ; i ++)
29+ {
30+ for (int j = 0 ; j < patternHeight ; j ++)
31+ {
32+ //condition for first and last line of the pattern
33+ //also middle of the line
34+ if ((i == 0 || i == patternHeight - 1 ) && (j != patternHeight -j -1 )) {
35+ System .out .printf ("$" );
36+ } else if (j == patternHeight / 2 || (i == 0 || i == patternHeight - 1 )) {
37+ System .out .printf ("##" );
38+ }
39+ else {
40+ //spacing for perfect alignment
41+ System .out .printf (" " );
42+ }
43+ }
44+ //shifting to new line after filling the current line pattern
45+ System .out .printf ("\n " );
46+ }
47+ }
48+
49+ //main method
50+ public static void main (String [] args ) {
51+
52+ Scanner sc = new Scanner (System .in );
53+
54+ System .out .println ("Please specify the height of the alphabet and keep that integer odd." );
55+
56+ //taking user input
57+ int patternHeight = sc .nextInt ();
58+
59+ if (height % 2 == 0 ) {
60+ System .out .println ("Please specify any odd integer for a better view." );
61+ } else {
62+ printI (patternHeight );
63+ }
64+
65+ //closed scanner
66+ sc .close ();
67+ }
68+ }
You can’t perform that action at this time.
0 commit comments