A string of charaters were given. Find the highest
occurance of a character and display that character.
eg.: INPUT: AEGBCNAVNEETGUPTAEDAGPE
Answer Posted / arpita
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
public class TestClass1 {
public static void main(String[] args) {
HashMap<Character, Integer> hm = new HashMap<Character,
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<Character> s = hm.keySet();
Iterator<Character> 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 |
Post New Answer View All Answers
in IBM PC -AT.WAT AT REFERS TO?
what is the diff bw sql direct and jdbc update can't we do select and updating operation in sql direct
write a sql qwery which include joining of two tables 4 marks mainframe
can we use commit,rollback in triggers and how?
What is easiest way to get the PL/i compiler,I didn't have found the compiler in my library. Is there any extra cost if we want to access the PL/1 programs?Actually we r having Mainframe rented training Ids
10.Define filters,binary to hexadecimal,hexadecimal to decimal?
how do we provide security for web services
3 members in a pf.how we read 3 members without using ovrdbf.using rg pgms....
what is session state?
Outline the two important features of a terminating recursion. Any ideas?
define profiler???
What are the Short cut Keys of Tally ERP?
In loading programs into memory, what is the difference between load-time dynamic linking and run-time dynamic linking?
what are the things i had to say in personal introduction in hr round mail me to prasanna.1867@rediff.com
How can recruiter justified that the candidate is expert in Algorithm and datastructure for Software product development ?