Programming Examples

Java program to find the Maximum Occurrence character in given string


Write a Java Program to find the Maximum Occurrence character in given string

import java.util.*;
class MaxChar
{
    public static void main(String arr[])
    {
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter any String : ");
        String str=sc.nextLine();
        //str=str.toUpperCase();
        int count=0,max=0;
        char chr=str.charAt(0);
        for(int a=0;a<str.length();a++)
        {
            count=0;
            for(int b=0;b<str.length();b++)
            {
                if(str.charAt(a)==str.charAt(b))
                {
                    count++;
                }
            }
            if(count>=max)
            {
                max=count;
                chr=str.charAt(a);
            }
        }
        System.out.println("Maximum Occurrence Char is : "+chr+" and the number of Occurrence is "+max);
    }
}
Output

Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad