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 singleton service?
what is the difference between future and callable interface in java?
What is the significance of continue jump statement? Explain with an example.
What is meant by memory leak?
Which variables are stored in heap?
What is a java lambda expression?
Explain the features of interfaces in java?
What are the types of java languages?
How can you avoid serialization in child class if the base class is implementing the serializable interface?
What does this () mean in constructor chaining concept?
What is a pattern what is an anti pattern?
What is isa relationship?
Is there any way to skip finally block of exception even if some exception occurs in the exception block?
Explain importance of throws keyword in java?
Explain what is Marker interface?