diff --git a/Programming/Java/HighestFrequencyCharacter/HighestFrequencyCharacter.java b/Programming/Java/HighestFrequencyCharacter/HighestFrequencyCharacter.java new file mode 100644 index 0000000..7584281 --- /dev/null +++ b/Programming/Java/HighestFrequencyCharacter/HighestFrequencyCharacter.java @@ -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 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); + + } +}