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
Is class is a abstract datatype in java?
what are resources in case of Threads
How do you pass variables forwrd to future CECI sessions
A good website has the following conditions It should be interactive. It should contain at least 20 images. Title cannot be null and should contain at least 10 letters other than spaces and hyphen (-). The keywords should contain atleast three among the following list : "design", "Graphics", "lovely", "beautiful", "amazing" and "mesmerising" Write a method: boolean isGoodWebsite(boolean isInteractive, int numOfImages, String title,String keywords[]) isInteractive whether the site is interactive or not numOfImages Number of images on the website title Title of the website keywords Array of keywords in the website.
what is the work of 1tier,2tier,&ntier? Plz Explain it!
I m new to the dbms. Recently i came across words clustered indexes & nonclustered indexes but i dont know what is this all about & whats the difference between them.. So please help me!!!!!!!!
what is the last ant version you worked?how to get it
What ports must be open for DCOM over a firewall? What is the purpose of Port 135?
How will you prove that java swing is multithreaded?
What is test execution and when will we start execution please send me one example for this question
what is diff bet ref variable & instance of class
when we use mantis? how learn mantis?
How to create a new dataset only duplicate observations in proc sort procedure?
can we retrieve only integer/String type columns from a table,if yes how?
what is delimiter in sas ?