sorry about the format. I'm typing it from the phone keyboard only, so ignore the format ^_^
--> Code working fine on ide. But it's 3rd condition indicating me not to repeat displaying same bytes.
package com.codegym.task.task18.task1803;
import java.io.*;
import java.util.*;
/*
Most frequent bytes
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
List<Integer> list = new ArrayList<>();
List<Integer> list1 = new ArrayList<>();
String fileName = reader.readLine();
reader.close();
InputStream inStream = new FileInputStream(fileName);
while(inStream.available()>0){
int data=inStream.read();
list.add(data);
}
inStream.close();
int count=0;
int sum=0;
for(int i=0; i<list.size();i++){
for(int j=i+1; i<list.size(); i++){
if(list.get(i)==list.get(j)){
count++;
}
}
if(count>sum){
sum=count;
list1.clear();
list1.add(list.get(i));
count=0;
}
else if(count==sum){
list1.add(list.get(i));
}
else{
count=0;
}
}
for(int x : list1){
System.out.print(x+" ");
}
}
}