File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33/*
44Write a program to print letter H exactly as shown below -
5- $$$$$##$$$$$
6- ##
7- ##
8- ##
9- ##
10- ##
11- ##
12- ##
13- ##
14- ##
15- $$$$$##$$$$$
5+
6+ $$$$$##$$$$$
7+ ##
8+ ##
9+ ##
10+ ##
11+ ##
12+ ##
13+ ##
14+ ##
15+ ##
16+ $$$$$##$$$$$
1617*/
1718
1819
2122public class Letter_I {
2223
2324 // main logic
24- public static void printI (int height )
25+ public static void printI (int patternHeight )
2526 {
26- for (int i = 0 ; i < height ; i ++)
27+
28+ for (int i = 0 ; i < patternHeight ; i ++)
2729 {
28- for (int j = 0 ; j < height ; j ++)
30+ for (int j = 0 ; j < patternHeight ; j ++)
2931 {
30- if ((i == 0 || i == height - 1 ) && (j != height -j -1 )) {
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 )) {
3135 System .out .printf ("$" );
32- } else if (j == height / 2 || (i == 0 || i == height - 1 )) {
36+ } else if (j == patternHeight / 2 || (i == 0 || i == patternHeight - 1 )) {
3337 System .out .printf ("##" );
3438 }
3539 else {
40+ //spacing for perfect alignment
3641 System .out .printf (" " );
3742 }
3843 }
44+ //shifting to new line after filling the current line pattern
3945 System .out .printf ("\n " );
4046 }
4147 }
4248
49+ //main method
4350 public static void main (String [] args ) {
4451
4552 Scanner sc = new Scanner (System .in );
4653
4754 System .out .println ("Please specify the height of the alphabet and keep that integer odd." );
4855
49- int height = sc .nextInt ();
56+
57+ int patternHeight = sc .nextInt ();
58+
5059 if (height % 2 == 0 ) {
5160 System .out .println ("Please specify any odd integer for a better view." );
5261 } else {
53- printI (height );
62+ printI (patternHeight );
5463 }
5564
5665 sc .close ();
You can’t perform that action at this time.
0 commit comments