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


Please Help Members By Posting Answers For Below Questions

Difference between views and index in sas programming

1216


it is a language or tools?

1804


i am exeprienced person what is selection process

1341


How do you pass variables forwrd to future CECI sessions

4265


What are the tasks performed by a Team Lead

2550


write the a cl program with the following specification A. Accept 2 parameters-date and date type B. if date type is J then convert date to *MDY format C. if date type is M convert date to *JUL format 4.send a program message with the value of converted date Please explain for each with coding?

2381


what is meant by life cycle of a business

1884


what is d main diff between the java and .net framework

1728


Write a shell program. Enter number of days from keyboard. Find out the number of years, month and days it contains

1769


how CLR identify vb file?

2697


I want Ada programming language books. Could anyone post me any link for that?

3142


WHat is execution in manual testing and when will we start execution and what language we use in execution

1671


when will triggars the at new event in abap and web dybn pro?

1705


how do we provide security for web services

2036


Write a program to show polymorphism.

848