-
Notifications
You must be signed in to change notification settings - Fork 0
/
week13_1.java
94 lines (46 loc) · 1.13 KB
/
week13_1.java
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import java.util.Scanner;
class Histogram{
String readString() {
StringBuffer sb = new StringBuffer();
Scanner scanner = new Scanner(System.in);
while(true) {
String line = scanner.nextLine();
if(line.equals(";")) {
break;
}
sb.append(line);
}
return sb.toString();
}
void countAlphaBet(String str, int len) {
String s = str.toUpperCase();
int [] cA = new int [26];
for(int i =0; i < 26; i++) {
cA[i] = 0;
}
System.out.println();
System.out.println("히스토그램을 그립니다.");
for(int i =0; i < len; i++) {
if(s.charAt(i) >= 'A' && s.charAt(i) <= 'Z') {
cA[s.charAt(i)- 'A']++;
}
}
for(int i =0; i < 26; i++) {
char c = (char) ('A' + i);
System.out.print(c);
for(int j = 0; j < cA[i]; j++) {
System.out.print("-");
}
System.out.println();
}
}
}
public class week13_1 {
public static void main(String[] args) {
String str;
Histogram h = new Histogram();
System.out.println("영문 텍스트를 입력하고 세미콜론을 입력하세요.");
str = h.readString();
h.countAlphaBet(str, str.length());
}
}