Skip to content

Commit ef982ed

Browse files
Merge pull request #328 from iravimandalia/program-pattern-printing-I
Solution for pattern letter I in Java
2 parents 5a2f4f4 + de03e19 commit ef982ed

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

Pattern_Printing/Letter_I.java

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
}

0 commit comments

Comments
 (0)