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 happens to a static var that is defined within a method of a class?
What is the difference between length and length () in java?
Explain about static imports in java?
Why Java is not pure Object Oriented language?
What is the difference between array and array list in java?
Name some classes present in java.util.regex package.
What are the differences between throw and throws?
What is the concatenation operator in java?
What is finalize()? Is finalize() similar to a destructor?
What is a stack class in java ?
What is a Transient Object?
Why java is used everywhere?
What is the null?
What are daemon Threads in java?
Can you write a java class that could be used both as an applet as well as an application?