Skip to content

Commit 7e6d7c0

Browse files
print pattern
1 parent 8788e26 commit 7e6d7c0

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

Pattern_Printing/Letter_H.java

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
3+
Write a program to print letter H exactly as shown below -
4+
5+
## ##
6+
## ##
7+
## ##
8+
## ##
9+
## $ $ $ ##
10+
## ##
11+
## ##
12+
## ##
13+
## ##
14+
15+
*/
16+
17+
import java.util.*;
18+
19+
public class Letter_H{
20+
21+
public static void main(String args[]){
22+
23+
Scanner sc = new Scanner(System.in);
24+
int n = sc.nextInt();
25+
printPattern(n);
26+
sc.close();
27+
28+
}
29+
30+
static void printPattern(int N){
31+
32+
// Declaring the values of left,
33+
// middle, right side
34+
String left = "##", middle = "$", right = "##";
35+
36+
// Main Row Loop
37+
for (int row = 0; row < 2 * N - 1; row++) {
38+
39+
// Condition for the left Values
40+
if (row < N)
41+
System.out.print(left);
42+
else
43+
System.out.print(left);
44+
45+
// Loop for the middle values
46+
for (int col = 1; col < N - 1; col++) {
47+
48+
// Condition for the middleValues
49+
if (row != N - 1)
50+
51+
// Two spaces for perfect alignment
52+
System.out.print(" ");
53+
54+
else
55+
System.out.print(" " +middle);
56+
}
57+
58+
// Condition for the right Values
59+
if (row < N)
60+
System.out.print(" " + right);
61+
else
62+
System.out.print(" " + right);
63+
System.out.println();
64+
}
65+
66+
}
67+
}

0 commit comments

Comments
 (0)