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

How many types of threads are there in java?

504


Explain an intermediate language?

510


Is void a return type?

555


Can an object subclass another object?

557


How do you convert an int to a string in java?

546






What is the purpose of sizeof operator?

532


Where and how can you use a private constructor?

537


What is a boolean in java?

579


Is arraylist zero based?

559


Why Java doesn’t support multiple inheritance?

638


What are the advantages of java over C++?

719


Why map is used in java?

583


What is hash code collision?

593


Convert Binary tree to linked list.

591


How to pass arraylist to stored procedure in java?

550