[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Im really stuck, and deadline is in 3 hours. I need to write
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /wsr/ - Worksafe Requests

Thread replies: 7
Thread images: 1
File: java.png (85 KB, 1366x768) Image search: [Google]
java.png
85 KB, 1366x768
Im really stuck, and deadline is in 3 hours.
I need to write a method that returns an int which is the number of runs in this sequence of coins
(a run is a block of coins all showing the same face, so for example in HHTHHHTTT
there are four runs namely HH, T, HHH, and TTT. Pic is my current method.
Any help is appreciated
>>
It looks like you're trying to compare the current letter of the string to the next one to see if it's a run, but what's happening in your if statement is that you're adding to count for every consecutive item in each run instead.
Change it to !=, and you should have your counter.
>>
>>77870
You'll have to add one to it
>>
>>77872
I'm not OP btw
>>
>>77870
This anon has most of the idea, but for this to fully work, you need to initialize the count variable as 1 and not 0.
>>
>>77872
Since the final step of the for loop will compare the last segment of the string to something off the string (most likely garbage data), that covers the 1 extra.
>>
>>77883
Oh wait, no, that's right. The < s.length prevents that. The others are right, initialize as 1 and put in a check for null strings before the loop.
Thread replies: 7
Thread images: 1

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.