arpita


{ City } noida
< Country > india
* Profession * software engineer
User No # 103565
Total Questions Posted # 0
Total Answers Posted # 1

Total Answers Posted for My Questions # 0
Total Views for My Questions # 0

Users Marked my Answers as Correct # 3
Users Marked my Answers as Wrong # 1
Questions / { arpita }
Questions Answers Category Views Company eMail




Answers / { arpita }

Question { Nagarro, 15545 }

A string of charaters were given. Find the highest
occurance of a character and display that character.
eg.: INPUT: AEGBCNAVNEETGUPTAEDAGPE


Answer

import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

public class TestClass1 {
public static void main(String[] args) {
HashMap hm = new HashMap Integer>();
String str = "AABBBCCZX";
if (str != null) {
char[] charArray = str.toCharArray();
for (char ch : charArray) {
int counter = 0;
for (int j = 0; j < charArray.length; j++) {
if (ch == charArray[j]) {
counter = counter + 1;
}
}
hm.put(ch, counter);
}

Set s = hm.keySet();
Iterator itr = s.iterator();
while (itr.hasNext()) {
char key = (char) itr.next();
System.out.println("Character : " + key + " Occurence : "
+ hm.get(key));
}
}

}
}

Is This Answer Correct ?    3 Yes 1 No