Max Frequency Character testcase

my code is not passing the two test cases i don’t know why.please tell the error
the code is
import java.util.*;
public class Main {
public static void main(String args[]) {

	Scanner scn=new Scanner(System.in);
	String str=scn.nextLine();
	StringBuilder sb=new StringBuilder(str);
	int[]freq=new int[sb.length()];
	for(int i=0;i<sb.length()-1;i++) {
		freq[i]=1;
		for(int j=i+1;j<=sb.length()-1;j++) {
			if(sb.charAt(i)==sb.charAt(j)) {
				freq[i]++;
				sb.setCharAt(j,'0');
			}
		}
	}
	int max=freq[0];
	int index=0;
	for(int i=0;i<=freq.length-1;i++) {
		if(freq[i]>max) {
			max=freq[i];
			index=i;
		}
	}
	System.out.println(sb.charAt(index));

}

}

@vaibhavgupta.1919 Hey vaibhav , try this input “abababababababa” and try to solve your code mistake by dry running your code.