解题思路:
注意事项:
参考代码:
import java.awt.List; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Scanner; public class Text01 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int len = sc.nextInt(); //LinkedHashMap不自动排序集合 //HashMap自动排序集合 HashMap<Integer, Integer> ha = new HashMap<Integer, Integer>(); for (int i = 0; i < len; i++) { int count = sc.nextInt(); if (ha.containsKey(count)) { ha.put(count, ha.get(count)+1); } else { ha.put(count, 1);//count代表这个数,1代表出现的次数 } } for (int i : ha.keySet()) { System.out.println(i+" "+ha.get(i)); } } }
0.0分
3 人评分