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

public class Test {

public static void main(String args[]) {
String s = "UNDERSTAND";
System.out.println("String " + s);
for (int i = 0; i < s.length(); i++) {
int counter = 1;
for (int j = i + 1; j < s.length(); j++) {

if (s.charAt(i) == s.charAt(j)) {
counter++;
}

}
System.out.println(s.charAt(i) + "-" + counter);
}

}

}

Is This Answer Correct ?    5 Yes 9 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is primitive data type in java?

911


How dead lock situation occurs in java and how you can identify it?

941


Outline the major features of java.

1032


What are pass by reference and pass by value?

930


What is this () in java?

973


What java is used for?

1025


What types of index data structures can you have in java?

1129


What is the name of the java compiler?

1004


Class c implements interface I containing method m1 and m2 declarations. Class c has provided implementation for method m2. Can I create an object of class c?

1542


What does three dots mean in java?

1059


Can we use string in switch case in java?

997


What is natural ordering in java?

899


How many types of design patterns are there?

1044


What is the abstraction?

969


What is java dot?

886