• Post Reply Bookmark Topic Watch Topic
  • New Topic

Write a java program for to count each repeated letters in the given String?  RSS feed

 
krishnamurthy durgam
Greenhorn
Posts: 13
Hibernate Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


for example if the given string is: The world is running java technology?

Ans:
T is =2
h is=2
e is=2
w is=1
n= 4

like wise i need out put of the program?

please help to this program with clearly ?
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you post your question with a bit more clarity? Read this page http://www.coderanch.com/how-to/java/HowToAskQuestionsOnJavaRanch first!
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We are NotACodeMill. If you are stuck then please explain your problem and we will help you but we won't write the code for you.
 
Robert D. Smith
Ranch Hand
Posts: 221
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been pondering this assignment for several hours now. It won't leave me alone. The problem is I have no clue on how to approach this.

There are the obvious, newb ways of doing this. Create a 26 element 2D array, then just read back the values, skipping the empty/null elements. There is the brute force method of a switch statement wiht 36 cases and 36 counters. Hmm, maybe something like int myCounter[36] and just increment the elements.

I'm sure there is a better way to approach this, but I'm not familiar enough with the language yet. I don't really understand the various collections -- hashmap, list array, etc.

Any hints on a possible approach that is a bit more elegant than my idiot example?

Regards,
Robert
[This is not a class assignment. I' am merely intrigued by the problem.]
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Go to the Java Tutorials and read about all the different types of collection.
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you use an array, you might use the letters as the indices. Remember a char is not a letter but a number, so you can do arithmetic on it.
 
Jayesh A Lalwani
Rancher
Posts: 2762
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Robert D. Smith wrote:

Hmm, maybe something like int myCounter[36] and just increment the elements.


i like it!. The question is why don't you like it? What do you think can be improved? What is the drawback of this solution?
 
krishnamurthy durgam
Greenhorn
Posts: 13
Hibernate Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi friends finally i got the answer from Coderanch it self thanks to helping me


this is my answer wt i am lokking
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!