写一个程序统计输入字符串中以“,”分隔的各种单词出现的次数。例如:输入的字符串为“java,java,j2ee,ibm,j2ee,ibm,j2me,jav...
程序员文章站
2022-05-28 09:40:36
...
public class Test3 {
public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
//输出提示语
System.out.println("请输入字符串 附:字符串之间用,隔开");
//读取输入字符串
String temp=br.readLine();
Map maps = new HashMap();
String[] templist = temp.split(",");
for(int i = 0 ; i < templist.length;i++){
//准备放map
String t = templist[i];
//判断key
boolean is = maps.containsKey(t);
if(is == true){
//++1
Integer vs = (Integer)maps.get(t);
vs++;
maps.put(t, vs);
}else{
//放`1
maps.put(t, 1);
}
}
System.out.println(maps);
}
}
上一篇: Ubuntu 15.10 安装 Rabbitvcs
下一篇: java反射机制实例