Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] arg) {
- Scanner str = new Scanner(System.in);
- System.out.println("Enter the string:");
- String inputStr = str.nextLine();
- inputStr = inputStr.replace(" ","");
- Map<Character, Integer> dictionary = new HashMap<Character, Integer>();
- for (int i = 0; i < inputStr.length(); i++) {
- char symbol = inputStr.charAt(i);
- int count = 0;
- if (dictionary.get(symbol) != null){
- count = dictionary.get(symbol);
- }
- count++;
- dictionary.put(symbol, count);
- }
- System.out.println(dictionary.entrySet());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement