Objektorientierte Programmierung WS 2013/2014 - Datei WordCount2.java
import java.util.TreeMap;
public class WordCount2
{ private TreeMap<String, Integer> tm;
public WordCount2() {
tm = new TreeMap<String, Integer>();
}
public void countMe(String s) {
Integer freq = tm.get(s);
tm.put(s, (freq == null) ? 1 : freq + 1);
}
public void stat() {
System.out.print(tm.size() + " distinct words: ");
System.out.println(tm);
}
public static void main(String[] args) {
WordCount2 wl = new WordCount2();
for (String a : args) {
wl.countMe(a.toUpperCase());
}
wl.stat();
}
}
/* Kommandozeilenargumente: To be or not to be
Ausgabe: 4 distinct words: {BE=2, NOT=1, OR=1, TO=2}
*/
Generiert mit Camelot | Probleme mit Camelot? | Geändert am: 05.12.2013


