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


Please Help Members By Posting Answers For Below Questions

What is data member in java?

509


What are conditionals and its types?

594


What is the difference between numeric and integer?

515


What are the different data types in java?

536


How do you reverse a list?

558






What is deserialization?

589


What is the purpose of the enableevents() method in java programming?

595


What is the association?

557


What are the types of methodology?

518


What is the purpose of format function?

630


What is the use of isempty in java?

543


What is a classloader in java?

538


What is initial size of arraylist in java?

539


Explain about exception propagation?

589


What are autoboxing and unboxing? When does it occur?

536