Strings-Max Frequency Character

Can you please tell me what’s wrong with my code as I’m getting two cases failed.
//code

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.next();
int max=0;
String str1 = “”;
for(int i=0;i<str.length();i++) {
int count = 1;

		while(i<str.length()-1 && str.charAt(i)==str.charAt(i+1)) {
			count++;
			i++;
		}
		
		if(max<count) {
			max=count;	
			
            str1=str1+str.charAt(i);
		}
       
	}
    System.out.print(str1);

}

}

@dishant
You are always printing your first character.
Input:
Aaa
Output:
Aa

You can create an int array of 256 size. And increment it by 1 for every element that occurs and later print the max freq char.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.