I have a simple program that reads two .txt files and prints out the number of u
ID: 3528187 • Letter: I
Question
I have a simple program that reads two .txt files and prints out the number of unique words in each file. I need to write a HashMap that counts the alphabetical characters and prints the three most common and their counts from either file. So basically this was the original question: "Write a character counting method, public static Map getCounts(FileInputStream input), that creates a Map of character counts in a file. Report the three most common alphabetic characters (a-z) and their counts in each file (moby.txt and hamlet.txt).
Here is the code I have so far, I'm having trouble counting characters instead of strings:
public static Map getCounts(FileInputStream input){
Map<String, Integer> map = new HashMap<String, Integer>();
String string;
for(int i = 0; i < string.length(); i++){
char c = (String) (i);
Integer val = map.get(new String());
if(val != null){
map.put(c, new Integer(val + 1));
}else{
map.put(c,1);
}
}
}
Explanation / Answer
http://stackoverflow.com/questions/2197287/problem-counting-in-mapstring-integer
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.