Results 1 to 3 of 3
Thread: Count Reoccurring Characters
- 04-14-2011, 02:35 PM #1Member
- Join Date
- Apr 2011
- Rep Power
Count Reoccurring Characters
Hi guys I'm a little stuck with this so any suggestions would be great.
My goal is to analyze a character arraylist such as xxxxxxaaaa and then turn it into x6a4. This means basically for every time a character repeats it counts it and then prints the character and how many times in a row it repeats.
Here's how I think I can do however I don't feel like this is the best way to accomplish it. If anyone could provide suggestions to do it more efficiently that would be great.
I'll have a for loop which will continue until it has reached the size of the initial arraylist. I have a counter variable to keep track of the number of times the character appears so far.
It then has an if statement to compare the current element in the array list to the previous one. If they match it will increase the counter variable if not it will print the previous character and the total value of the counter variable. It will then set the counter variable back to zero.
Any suggestions on how to improve? Thanks in advance.
- 04-14-2011, 02:38 PM #2
What happened when you tried that? Did it work? Did it have any problems?
I'm not trying to be a smartass. Writing a simple version of that program should take no longer than a half hour, but waiting on responses (which might be wrong anyway) could take a few days.
I'd say your best bet is to write a version of your program, then post it with any specific questions or problems you had. You're much more likely to get advice on improving your algorithm once you actually have the code written.
- 04-14-2011, 03:20 PM #3
- Join Date
- Sep 2008
- Voorschoten, the Netherlands
- Blog Entries
- Rep Power
JosBuild a wall around Donald Trump; I'll pay for it.
- By java_student88 in forum Advanced JavaReplies: 9Last Post: 03-28-2011, 12:00 PM
- By tj_wolf2 in forum New To JavaReplies: 8Last Post: 03-14-2011, 06:07 PM
- By caryr in forum AWT / SwingReplies: 5Last Post: 06-28-2009, 08:33 PM
- By TheRocket in forum New To JavaReplies: 3Last Post: 11-20-2008, 02:25 PM
- By Java Tip in forum Java TipReplies: 0Last Post: 02-11-2008, 09:49 AM