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

Given an array all of whose elements are positive numbers, find the maximum sum of a subsequence with the constraint that no 2 numbers in the sequence should be adjacent in the array. So 3 2 7 10 should return 13 (sum of 3 and 10) or 3 2 5 10 7 should return 15 (sum of 3, 5 and 7)

760


What is the merger sort principle and its time complexity.

640


Hi All, Can any one please send me the difference between informatica 7i and 8i versions, Thanks in advance. vinod

1535


what is an INI file?

1596


What is test execution and when will we start execution please send me one example for this question

1429






In mainframe SDSF, Can we copy the list of jobs currently executing in SDSF in to a seperate DATASET...?

1848


Given an array of size n. It contains numbers in the range 1 to n. Each number is present at least once except for 1 number. Find the missing number

728


Difference between views and index in sas programming

1028


I want to pass .pdf files as OlE Object to crystal report through VB6. Please any one guid me...

2596


what is the basic and unique feature of dotnet

1716


Can anyone send me NIC question papers alongwith answers on nidhi1485@yahoo.co.in? Urgently needed.. Thanks in advance

1840


what will we require to build project with the help of oracle

1387


How to merge Action Form with Dyna Action Form in Struts.

1896


Iam using Microsoft Visual Studio to create a system for mobile store I want to know how to calculate mobile price that the customer buy and how to reduce quantity from the data base that we have for mobile .And also how to calculate revnue for each mobile and revnue for the total mobile

1482


As per interoperatbility programs written in one language can be used by other language. How can we restrict the features of one language (say C#) in the programmer written in another language (say VB)..for example we have some features like operator overloading which is possible C#.NET (not in VB.NET), how can we restrict that when we are using this code in VB.NET.

1455