package demo_map; import java.util.*; import java.util.Map.Entry; public class Charcount { public static void main(String[] args) { System.out.println("please code"); Scanner sc=new Scanner(System.in); String str=sc.next(); findChar(str); } public static void findChar(String str){ char[] arr=str.toCharArray(); HashMap<Character,Integer> h1=new HashMap<>(); if (arr==null){ System.out.println("wrong"); }else { for (int i = 0; i <arr.length ; i++) { if (h1.containsKey(arr[i])==true){ Integer v=h1.get(arr[i]); v++; h1.put(arr[i],v); }else { h1.put(arr[i],1); } } } Set<Map.Entry<Character,Integer>> set=h1.entrySet(); for (Map.Entry<Character,Integer> entry:set) { System.out.println(entry.getKey()+": "+entry.getValue()); } } }