How do I make Set Interface work in the code below to find the max char.
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner scn = new Scanner(System.in);
String str = scn.nextLine();
}
public static char maxFreq(String str) {
HashMap<Character,Integer> map = new HashMap<>();
for(int i=0;i<str.length();i++) {
char cc = str.charAt(i);
if(map.containsKey(cc)) {
int ov = map.get(cc);
int nv = ov+1;
}else {
map.put(cc,1);
}
}
int max=0;
char maxChar=’\0’;
Set<Map.Entry<Character,Integer>> entries = map.entrySet();
for(Map.Entry<Character,Integer> entry : entries) {
if(map.getValue() > max) {
max = map.getValue();
maxChar = map.getKey();
}
}
return maxChar;
}
}