Java Program to Print Maximum Occurred Character in String

print maximum occurred character in string

In this tutorial, we will learn to print the character which occurs the most. For any input string, we have to check the number of occurrences of each character and print the character with the maximum number of occurrences.

For example

Case1: If the user enters the string ‘Python is fun’

The output should be ‘n’, as the character ‘n’, occurs 2 times which is maximum in all other character occurrences in the string.

Case2: If the user enters the string ‘Engineer’

The output should be ‘e’, as the characters ‘e’, occurs 3 times which is maximum in all other character occurrences in the string.

Java Program to Print Maximum Occurred Character in String

Output

Explanation

In this output, for the input string ‘Quescol Website’, the array input elements as {‘Q’, ‘u’, ‘e’, ‘s’, ‘c’, ‘o’, ‘l’, ‘ ‘, ‘W’, ‘e’, ‘b’, ‘s’, ‘i’, ‘t’, ‘e’}. max_count returns the elements which appears maximum times as the element of array which is ‘e’ in this case repeated 3 times.