日期:2014-05-20  浏览次数:20708 次

帮忙用java编写一个输入字符,并能自动统计每个字符输入的次数的程序
我新手,老是出错,又找不到原因,帮忙写一个,非常感谢,参考学习下,谢谢了..

------解决方案--------------------
import java.util.*;
import java.io.*;

public class CountChar {

public static void main(String[] args){

HashMap <Character,Integer> charMap = new HashMap <Character,Integer> ();
InputStreamReader in = new InputStreamReader(System.in);
Character c = null;
Integer count = null ;
try{
c = Character.valueOf((char)in.read());
while(c.charValue()!= '# '){
count = charMap.get(c);
charMap.put(c,count==null ? 1:count+1);
c = Character.valueOf((char)in.read());
}
}catch(IOException e){
System.out.println( "Error!!! ");
System.exit(-1);
}

System.out.println(charMap);
}

}

收分!!!!!