Skip to content

Commit

Permalink
Create HighestFrequencyCharacter.java (aditya109#517)
Browse files Browse the repository at this point in the history
  • Loading branch information
JainStuti25 authored Oct 10, 2021
1 parent 4588f76 commit dd852eb
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.company;
import java.util.HashMap;
import java.util.Scanner;

//Highest Frequency Character

public class HighestFrequencyCharacter {
public static void main(String[] args) {

Scanner sc = new Scanner(System.in);
String str = sc.nextLine();

HashMap<Character, Integer> hm = new HashMap<>();
for (int i = 0; i < str.length(); i++){
char ch = str.charAt(i);

if (hm.containsKey(ch)){
int of = hm.get(ch);
int nf = of+1;
hm.put(ch,nf);
}
else{
hm.put(ch,1);
}
}

char mfc = str.charAt(0);
for (Character key : hm.keySet()){
if(hm.get(key)>hm.get(mfc)){
mfc=key;
}
}
System.out.println(mfc);

}
}

0 comments on commit dd852eb

Please sign in to comment.