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 / pradeep mishra
public class CountOccur {
String str="ANAND";
int c1=0;
int c2=0;
int c3=0;
String retun=null;
public static void main(String[] args) {
CountOccur co=new CountOccur();
System.out.println("Ocurrence "+co.Test());
}
public String Test() {
for( int i=0;i<str.length();i++){
if(str.charAt(i)=='A')
c1++;
if(str.charAt(i)=='N')
c2++;
if(str.charAt(i)=='D')
c3++;
}
retun="A"+c1+"N"+c2+"D"+c3;
return retun;
}
}
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
What is main method?
What is the difference between the prefix and postfix forms of the ++ operator?
Which command from the jdk compiles a java program?
Is void a type?
How many JVMs can run on a single machine and what is the meaning of Just-In-Time (JIT) compiler?
What is a line separator in java?
Why java is used everywhere?
What is static and final keyword in java?
Explain creating threads by implementing runnable class?
What is a predicate method?
What does the string method compareto () do?
What is identifier give example?
What is hashing principle in java?
What is class forname?
Can you use abstract and final both with a method?