String Question 11
Question 21. Write a Program to print maximum occuring character.
Program
class Solution { public static char getMaxOccuringChar(String line) { int []arr=new int[26]; for(int i=0;i<=line.length()-1;i++){ arr[line.charAt(i)-97]++; } int max=0; int maxindex=-1; for(int i=0;i<26;i++){ if(arr[i] >max){ max=arr[i]; maxindex=i; } } return (char)(maxindex+97); } } |