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

import java.util.Vector;

class test
{
public static void main(String []dasf)
{
String s="Manikandan,GTEC,vellore" ;
int count,a,c;
for(int i=0;i<s.length();i++)
{
count=0;c=0;a=0;
for(int j=0;j<s.length();j++) //counting
{
if(s.charAt(i)==(s.charAt(j)))
{
count++;
}

} while(a<=i)// checking duplicate
{
if(s.charAt(i)==s.charAt(a))
{
c++;
}
a++;
}
if(c==1)
System.out.println(s.charAt(i)+" = "+count);


}


}
}
o/p:
M-1
a-3
n-3
i-1
k-1
d-1
,-2
G-1
T-1
E-1
C-1
v-1
e-2
l-2
o-1
r-1
i done it for case sensitive.

In the checking Duplicate code "c" will increment more than
one if duplicate presents.
if any doubt in above code contact me at
manikandansit@gmail.com

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can you override a final method?

981


how can you catch multiple exceptions in java?

967


When is the finalize() called? What is the purpose of finalization?

1014


What is byte code and why is it important to java’s use for internet programming?

1047


Is sizeof a keyword in java programming?

1013


Which sorting algorithm is in place?

902


What is the difference between C++ and Java and your preferences?

1061


What is static block?

1057


What is the basic difference between string and stringbuffer object?

1023


What is final class?

955


Why are parameters used in functions?

939


Can inner class extend any class?

1007


Can a class declared as private be accessed outside it’s package?

947


How many types of exception can occur in a java program?

924


How can constructor chaining be done by using the super keyword?

1036