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