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


Please Help Members By Posting Answers For Below Questions

How do you declare a destructor in java?

512


Can inner class final?

637


how to deploy tomcatserver to weblogic server? write d following steps?

1455


Define canvas?

570


Write a program to search a number in the given list of numbers.

634






What is the meaning of I ++ in java?

610


What are the legal operands of the instanceof operator?

569


Is math an abstract class in java?

540


Explain garbage collection in java?

549


Is map sorted in java?

572


What are the different types of java?

561


can any body body expalin best definitions & best real time exaples for opps concepts.

1843


Name some classes present in java.util.regex package.

610


What is the difference between the file and randomaccessfile classes?

540


Are strings immutable in java?

527