importjava.util.HashMap;importjava.util.Iterator;importjava.util.Map;importjava.util.Scanner;importjava.util.Set;publicclassClass1{publicstaticvoidT(Stringstr){char[]a=st...
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
public class Class1 {
public static void T(String str){
char[] a=str.toCharArray();
Map map = new HashMap();
for(int i=0;i
if(map.containsKey(a[i])){
map.put(a[i],1);
}
else{
Integer k=map.get(a[i]);
map.put(a[i], (k+1));
}
}
Set set = map.keySet();//返回所有key值组成的集合
Iterator ite = set.iterator();
while(ite.hasNext()){
System.out.print(ite.next()+"\t"+map.get(ite.next())+"\t");
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("字符串 ");
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
T(str);
}
}
展开