统计你的手机号码中出现次数最多的数字,并打印出此数字及其出现次数

public class Mobile {
public static void show() {
System.out.println("请输入你的手机号:");
Scanner scanner = new Scanner(System.in);
String s = scanner.next();
char[] number = s.toCharArray();
//number = {'1','3','9',}
Map map = new HashMap();
for (int i = 0; i < number.length; i++) {
char z = number[i];
if (!map.containsKey(z)) {
map.put(z, 1);
} else {
int count = map.get(z);
count++;
map.put(z, count);
}
}
Set> set = map.entrySet();


for (Entry entry : set) {


System.out.println("数字" + entry.getKey() + "出现的次数为"
+ entry.getValue() + "次");
}

Collection collection = map.values();
int max = Collections.max(collection);


Set> set2 = map.entrySet();


for (Entry entry : set2) {


if (entry.getValue() == max) {


System.out.println("数字" + entry.getKey() + "出现的次数最多,为:"
+ max + "次");
}
}
}


public static void main(String[] args) {
// TODO Auto-generated method stub
show();
}


}

你可能感兴趣的:(统计你的手机号码中出现次数最多的数字,并打印出此数字及其出现次数)