我实现了输出重复最频繁的字节啊,到底是哪里出了问题啊?
package zh.codegym.task.task18.task1803;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/*
使用最频繁的字节
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
String fileName=reader.readLine();
FileInputStream inputStream=new FileInputStream(fileName);
Map<Integer,Integer> map=new HashMap<>();
List<Integer> list=new ArrayList<>();
while (inputStream.available()>0){
int data=inputStream.read();
map.put(data,0);
list.add(data);
}
for(int i=0;i<map.size();i++){
for (Map.Entry<Integer,Integer> pair:map.entrySet()){
if(pair.getKey().equals(list.get(i))) map.put(pair.getKey(),pair.getValue()+1);
}
}
int max=0;
for (Map.Entry<Integer,Integer> pair:map.entrySet()){
max=Math.max(max,pair.getValue());
}
for (Map.Entry<Integer,Integer> pair:map.entrySet()){
if(pair.getValue()==max) System.out.print(pair.getKey()+" ");
}
inputStream.close();
}
}