title: Sort by number of apearances
body: <p>for example, I am given a word and I have to sort its letters by the number of occurrences in that word, if 2 letters appear the same number of times it will be sorted by the lexicographic minimum.
  For now, I have started to see how many times a letter appears in a word but from here I do not know exactly how to do it.
  The problem requires me to use BufferedReader and BufferedWriter.</p>
  
  <pre><code>import java.util.*;
  
  public class Main {
  public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      Map&lt;Character, Integer&gt; m = new HashMap&lt;&gt;();
      String s = sc.nextLine();
      for (int i = 0; i &lt; s.length(); ++i) {
          char c = s.charAt(i);
          if (m.containsKey(c))
              m.put(c, m.get(c) + 1);
          else
              m.put(c, 1);
      }
      for (char letter = 'a'; letter &lt;= 'z'; ++letter)
          if (m.containsKey(letter))
              System.out.println(letter + ": " + m.get(letter));
  }
  </code></pre>
  
  <p>For the moment I am posting what letters appear most often in the word, but I do not know how to sort them by the number of occurrences and in case there are two letters that appear at the same number of times with the minimum lexicographic.</p>