62,614
社区成员
发帖
与我相关
我的任务
分享
import java.util.HashMap;
import java.util.Map;
public class Test {
public static void main(String[] args) {
int[] a={2,3,4,3,5,15,44,33,66,3,7,7,9};
Map<Integer, Integer> m = new HashMap<Integer, Integer>();
for(int i = 0; i < a.length; i++){
if(!m.containsKey(a[i])){
m.put(a[i], 1);
}else{
m.put(a[i], m.get(a[i])+1);
}
}
}
}
public static void main(String args[]) {
int[] a = { 2, 3, 4, 3, 5, 15, 44, 33, 66, 3, 7, 7, 9 };
// sort
Arrays.sort(a);
// out
int currentValue = a[0], count = 0;
for (int i : a) {
if (i == currentValue) {
count++;
} else {
System.out.printf("%-3d出现次数为:%-3d\n", currentValue, count);
currentValue = i;
count = 1;
}
}
}
import java.util.HashMap;
import java.util.Map;
public class Test {
public static void main(String[] args) {
int[] a={2,3,4,3,5,15,44,33,66,3,7,7,9};
Map<Integer, Integer> m = new HashMap<Integer, Integer>();
for(int i = 0; i < a.length; i++){
if(!m.containsKey(a[i])){
m.put(a[i], 1);
}else{
m.put(a[i], m.get(a[i])+1);
}
}
}
}