package shuzu;
import java.util.HashMap;
import java.util.Map;
public class changpiao {
public static void main(String[] args) {
// TODO Auto-generated method stub
//唱票!!选班干部,现有票:
String str= "秦始皇,汉武帝,打工人,路人甲,"
+"秦始皇,打工人,路人甲,"
+"秦始皇,汉武帝,炮灰";
String []s = str.split(",");
System.out.println("总共有"+s.length+"张选票");
//字符串数组,每一个元素都是一个人名[姓名,票数]
//[(键1,值1)],
Map
for(int i=0;i
int k = mp.get(s[i]);
mp.replace(s[i],k+1);
}else{
mp.put(s[i],1);
}
}
//forEach
for(String key:mp.keySet()){
System.out.println(key+":"+mp.get(key));
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)