My code is giving incorrect answer most of the time. What is the mistake?
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner scn = new Scanner(System.in);
String str = scn.nextLine();
int [] charray = new int[26];
for(int i = 0;i < str.length();i++){
charray[str.charAt(i) - ‘a’]++;
}
int max = -1;
int index = 1;
for(int i = 0;i<=25;i++){
if(charray[i]>max){
max = charray[i];
index = i+1;
}
}
System.out.print(str.charAt(index));
}
}