Objektorientierte Programmierung WS 2013/2014 - Datei WordCount.java
import java.util.TreeMap;
public class WordCount extends TreeMap<String, Integer> {
public void countMe(String s) {
Integer freq = get(s);
put(s, (freq == null) ? 1 : freq + 1);
}
public void stat() {
System.out.print(size() + " distinct words: ");
System.out.println(this);
}
public static void main(String[] args) {
WordCount wl = new WordCount();
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


