Hi,
This is ravi i have a question like this i have string
"UNDERSTAND" now i want to count the letters how many times
it occures.i.e from the above string the out put should be
like this U-1,N-2,D-2,E-1,R-1,S-1,T-1,A-1.
how can i achieve this
Thnaks in advance for your response ..
Answer Posted / pal_ss
public class Test {
public static void main(String args[]) {
String s = "UNDERSTAND";
System.out.println("String " + s);
for (int i = 0; i < s.length(); i++) {
int counter = 1;
for (int j = i + 1; j < s.length(); j++) {
if (s.charAt(i) == s.charAt(j)) {
counter++;
}
}
System.out.println(s.charAt(i) + "-" + counter);
}
}
}
| Is This Answer Correct ? | 5 Yes | 9 No |
Post New Answer View All Answers
What is the difference between the final method and abstract method?
What does regex mean?
How many types of keywords are there?
Tell me how many ways are there to initialise an integer with a constant.
Explain the difference between call by refrence and call by value?
How destructors are defined in java?
When is finally block not called?
What is purpose of keyword void?
How big is a gigabyte?
How can u increase the heap size in the memory?
Explain static nested classes ?
What are static methods?
Can we serialize singleton class?
Which is illegal identifier in java?
What are the different types of inheritance in java?