Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Explain access specifiers?

1120


How can you handle java exceptions?

965


What are the methods to rectify ambiguities in the interfaces in JAVA?

1032


Give reasons supporting that string is immutable.

894


What is update method called?

1092


What is core java used for?

1054


What are alternatives to java serialization?

1054


Explain about complier design(phases)

1023


what is abstract class in Java?

1072


How does java enable high performance?

1091


Can the interface be final?

965


List any five features of java?

963


What is sizeof in java?

1052


Explain the difference between treeset and treemap in java?

925


What are the ways to instantiate the class class?

1058