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

Explain the importance of throws keyword in java?

569


What are the types of web technologies?

530


who can i handle multiple client in RMI

1444


Is java se open source?

574


What is the main use of generics in java?

510






How is java created?

537


What is the maximum size of list in java?

546


What is difference between string and stringbuffer?

498


Why is singleton class used?

528


What is a databasemetadata?

553


Explain about narrowing conversion in java?

570


Can a singleton class be inherited?

530


Is string a datatype?

552


What is a parameter in java?

548


What is the difference between super class & sub class?

567