Write program to print Hello World and print each character
address in that string and print how many times each
character is in that string?
Ex: H: 0 & 1
e:1 & 1
l :2,3,8 & 3
o:4,6 & 2
w:5 & 1
r: 7 & 1
d 9 & 1
Answer Posted / jishnu
Sorry I dont want to give a detailed answer here cos no one e is going to read the code.
You can use Map<Char,List<Integer>> counterMap
Iterate through the length of the string
for(int i=i; i<s.length();i++){
if(counterMap.get(s.getCharAt(i))==nul){
//First time
List<Integer> a= new ArrayList<Integer>();
a.add(i);
counterMap.put(s.getCharAt(i),a);
}else{
counterMap.get(s.getCharAt(i)).add(i);
}
//We can iterate through keySet or entrySet to show the result
}
Regards,
Jishnu
Is This Answer Correct ? | 3 Yes | 0 No |
Post New Answer View All Answers
What is meant by object oriented programming – oop?
Give me example of derived data types.
Write a java program that prints all the values given at command-line.
Can you explain the private protected field modifier?
design an lru cache in java?
What is __ init __ functions?
what is optional in java 8?
what is an objects lock and which objects have locks? : Java thread
which one is more efficient int x; 1. if(x==null) 2.if(null==x) state which one either 1 or 2?
What is method in research paper?
What is stack example?
How do you use find and replace?
What are the basic interfaces of java collections framework?
Can I uninstall java?
List two java ide’s?