-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHolidayCode6.java
More file actions
135 lines (108 loc) · 4.17 KB
/
HolidayCode6.java
File metadata and controls
135 lines (108 loc) · 4.17 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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import java.util.*;
import java.io.*;
public class HolidayCode6 {
public static char MostFrequent (HashMap<Character, Integer> charMap){//For Part 2, Least Frequent
//int max = 0;
int min = 999999;
char mostFreq = ' ';
for(char current : charMap.keySet()){
if(charMap.get(current) < min){
mostFreq = current;
min = charMap.get(current);
}
}
return mostFreq;
}
public static void main(String[] args){
try{
File file = new File("message.txt");
FileReader fileReader = new FileReader(file);
BufferedReader input = new BufferedReader(fileReader);
String line;
HashMap<Character, Integer> char1 = new HashMap<Character, Integer>();
HashMap<Character, Integer> char2 = new HashMap<Character, Integer>();
HashMap<Character, Integer> char3 = new HashMap<Character, Integer>();
HashMap<Character, Integer> char4 = new HashMap<Character, Integer>();
HashMap<Character, Integer> char5 = new HashMap<Character, Integer>();
HashMap<Character, Integer> char6 = new HashMap<Character, Integer>();
HashMap<Character, Integer> char7 = new HashMap<Character, Integer>();
HashMap<Character, Integer> char8 = new HashMap<Character, Integer>();
while((line = input.readLine()) != null){
char current = line.charAt(0);
if(char1.get(current) != null){
int value = char1.get(current);
value++;
char1.put(current, value);
} else {
char1.put(current, 1);
}
current = line.charAt(1);
if(char2.get(current) != null){
int value = char2.get(current);
value++;
char2.put(current, value);
} else {
char2.put(current, 1);
}
current = line.charAt(2);
if(char3.get(current) != null){
int value = char3.get(current);
value++;
char3.put(current, value);
} else {
char3.put(current, 1);
}
current = line.charAt(3);
if(char4.get(current) != null){
int value = char4.get(current);
value++;
char4.put(current, value);
} else {
char4.put(current, 1);
}
current = line.charAt(4);
if(char5.get(current) != null){
int value = char5.get(current);
value++;
char5.put(current, value);
} else {
char5.put(current, 1);
}
current = line.charAt(5);
if(char6.get(current) != null){
int value = char6.get(current);
value++;
char6.put(current, value);
} else {
char6.put(current, 1);
}
current = line.charAt(6);
if(char7.get(current) != null){
int value = char7.get(current);
value++;
char7.put(current, value);
} else {
char7.put(current, 1);
}
current = line.charAt(7);
if(char8.get(current) != null){
int value = char8.get(current);
value++;
char8.put(current, value);
} else {
char8.put(current, 1);
}
}
System.out.print(MostFrequent(char1));
System.out.print(MostFrequent(char2));
System.out.print(MostFrequent(char3));
System.out.print(MostFrequent(char4));
System.out.print(MostFrequent(char5));
System.out.print(MostFrequent(char6));
System.out.print(MostFrequent(char7));
System.out.println(MostFrequent(char8));
} catch (IOException error) { //Need this for using buffered readers
error.printStackTrace();
}
}
}