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.