Advertisement
Lusien_Lashans

Задача 1А Java

Sep 27th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. import java.util.HashMap;
  2. import java.util.Map;
  3. import java.util.Scanner;
  4.  
  5.  
  6. public class Main {
  7.  
  8.     public static void main(String[] arg) {
  9.         Scanner str = new Scanner(System.in);
  10.         System.out.println("Enter the string:");
  11.         String inputStr = str.nextLine();
  12.  
  13.         inputStr = inputStr.replace(" ","");
  14.  
  15.         Map<Character, Integer> dictionary = new HashMap<Character, Integer>();
  16.  
  17.  
  18.         for (int i = 0; i < inputStr.length(); i++) {
  19.             char symbol = inputStr.charAt(i);
  20.             int count = 0;
  21.             if (dictionary.get(symbol) != null){
  22.                 count = dictionary.get(symbol);
  23.             }
  24.             count++;
  25.             dictionary.put(symbol, count);
  26.         }
  27.  
  28.         System.out.println(dictionary.entrySet());
  29.  
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement