Can someone help me with this one? I do not really understand why there is still a problem with the 3rd requirment is not passing.
package pl.codegym.task.task18.task1804;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
/*
Najrzadziej występujące bajty
*/
public class Solution {
public static void main(String[] args) throws Exception {
FileInputStream fileToReadFrom = new FileInputStream(getFileName());
HashMap<Character, Integer> characterMap = new HashMap<>();
while (fileToReadFrom.available() > 0) {
Character symbol = (char) fileToReadFrom.read();
if (characterMap.containsKey(symbol)){
int newValue = characterMap.get(symbol) + 1;
characterMap.replace(symbol, characterMap.get(symbol), newValue);
}
else
characterMap.put(symbol, 1);
}
characterMap.put((char) fileToReadFrom.read(), 1);
fileToReadFrom.close();
int minimum = setMinimum(characterMap);
displayLetters(characterMap, minimum);
}
public static String getFileName() throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
return reader.readLine();
}
public static int setMinimum(HashMap<Character, Integer> map) {
int minimum = Integer.MAX_VALUE;
for (Character symbol : map.keySet())
if (minimum > map.get(symbol))
minimum = map.get(symbol);
return minimum;
}
public static void displayLetters(HashMap<Character, Integer> map, int min) {
String toDisplay = "";
for (Character symbol : map.keySet())
if (min == map.get(symbol))
toDisplay = toDisplay + " " + symbol;
System.out.println(toDisplay);
}
}