51,411
社区成员
发帖
与我相关
我的任务
分享
public static void main(String[] args) {
HashMap<Integer,Integer> map = new HashMap<>();
Scanner in = new Scanner(System.in);
for(int i=0;i<20;i++){
String a = in.nextLine();
int i = Integer.parseInt(a);
if((i>=0)&&(i<=10)){
if(map.containsKey(a)){
map.put(a,map.get(a)+1);
}else{
map.put(a,1);
}
}else{
continue;
}
}
for (HashMap.Entry<Integer, Integer> entry : map.entrySet()) {
System.out.println(entry.getKey() + " 出现了 " + entry.getValue() + "次");
}
}
public static void main(String[] args) {
HashMap<Integer,Integer> map = new HashMap<>();
Scanner in = new Scanner(System.in);
for(int i=0;i<20;i++){
int a = in.nextInt();
if(map.containsKey(a)){
map.put(a,map.get(a)+1);
}else{
map.put(a,1);
}
}
for (HashMap.Entry<Integer, Integer> entry : map.entrySet()) {
System.out.println(entry.getKey() + " 出现了 " + entry.getValue() + "次");
}
}