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 / john

public class Test {

public static void main (String a[]){
String s ="UNDERSTAND";
char rep[] = new char [s.length()];
StringBuffer rept=new StringBuffer();
boolean flag=false;

for(int i=0;i<s.length();i++){
int k=0;
for(int j=0;j<rept.length();j++){
if( s.charAt(i) == rept.charAt(j))
flag=true;
}
if(flag==false){
rept = rept.append(s.charAt(i));
}
}
System.out.println("Rept = "+rept);

for(int i=0;i<rept.length();i++){
char var= rept.charAt(i);
int counter=1;
for(int j=s.indexOf(var);j<s.lastIndexOf
(var);j++){
if(var == s.charAt(j)){
counter++;
}
}
System.out.println( " "+var+ " : "+counter);
}

}//main
}//Test

Is This Answer Correct ?    4 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What do you know about the garbate collector?

604


If a method is declared as protected, where may the method be accessed?

538


What is the function of http?

535


Explain about the dynamic behavior of core java?

638


Can we store variables in local blocks?

790






why java does not support unsigned keyword?

4271


How do you check if two given string are anagrams?

555


What is the difference between a constructor and a method?

572


Explain why wait(), notify() and notifyall() methods are in object class rather than in thread class?

565


What is a copy constructor in java?

583


When throws keyword is used?

584


What are static initalizers in java ?

586


What is used of static keyword in java?

594


Why string is not thread safe?

544


What is the difference between length and size in java?

501