Skip to content

Commit dbab99c

Browse files
committed
Solution for pattern letter I in Java
1 parent 7926402 commit dbab99c

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

Pattern_Printing/Letter_I.java

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
import java.util.Scanner;
20+
21+
public class Letter_I {
22+
23+
// main logic
24+
public static void printI(int height)
25+
{
26+
for (int i = 0; i < height; i++)
27+
{
28+
for (int j = 0; j < height; j++)
29+
{
30+
if ((i == 0 || i == height - 1) && (j != height-j-1)) {
31+
System.out.printf("$");
32+
} else if (j == height / 2 || (i == 0 || i == height - 1)) {
33+
System.out.printf("##");
34+
}
35+
else {
36+
System.out.printf(" ");
37+
}
38+
}
39+
System.out.printf("\n");
40+
}
41+
}
42+
43+
public static void main(String[] args) {
44+
45+
Scanner sc = new Scanner(System.in);
46+
47+
System.out.println("Please specify the height of the alphabet and keep that integer odd.");
48+
49+
int height = sc.nextInt();
50+
if(height % 2 == 0) {
51+
System.out.println("Please specify any odd integer for a better view.");
52+
} else {
53+
printI(height);
54+
}
55+
56+
sc.close();
57+
}
58+
}

0 commit comments

Comments
 (0)