Last active
October 16, 2018 08:14
-
-
Save lovasoa/f0372c9eb56cb2499e7ad6b9fd9ac626 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.company; | |
import java.io.PrintStream; | |
import java.util.HashMap; | |
import java.util.Map; | |
public class Main { | |
static void hist(String codes, PrintStream out) { | |
Map<Character, Integer> map = new HashMap<>(); | |
String letters = "uwxz"; | |
for (int i = 0; i < letters.length(); i++) | |
map.put(letters.charAt(i), 0); | |
for (int i = 0; i < codes.length(); i++) { | |
map.computeIfPresent(codes.charAt(i), (ch, count) -> count + 1); | |
} | |
for (Map.Entry<Character, Integer> me : map.entrySet()) { | |
Integer n = me.getValue(); | |
if (n > 0) { | |
out.format("%c %-5d%s%n", me.getKey(), n, iter(n)); | |
} | |
} | |
} | |
public static String iter(int n) { | |
StringBuilder billder = new StringBuilder(); | |
String a = "*"; | |
for (int i = 0; i < n; i++) { | |
billder.append(a); | |
} | |
return billder.toString(); | |
} | |
public static void main(String[] args) { | |
hist("axuwxzzzzzzzzzzz", System.out); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment