标签:com while catch img ann public todo key highlight
import java.io.File; import java.io.FileNotFoundException; import java.util.HashMap; import java.util.Map; import java.util.Scanner; import java.util.Set; public class S22_2 { public static void main(String[] args) { // TODO Auto-generated method stub Map<String,Integer> myMap = new HashMap<String,Integer>(); File myFile = new File("txt.txt"); try { Scanner input = new Scanner(myFile); while(input.hasNext()){ String str = input.next().toLowerCase(); if(myMap.get(str) == null){ myMap.put(str, 1); } else { int value = myMap.get(str).intValue(); value++; myMap.put(str,value); } } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } Set<Map.Entry<String, Integer>> entrySet = myMap.entrySet(); for(Map.Entry<String, Integer> entry:entrySet) System.out.println(entry.getKey() + "\t" + entry.getValue()); } }
标签:com while catch img ann public todo key highlight
原文地址:http://www.cnblogs.com/wanjiang/p/6052633.html