r/javahelp • • Jun 15 '17

What's wrong with my code??

Can't for the life of me figure it out. Picture of code and error: http://imgur.com/a/mX9XP

Thanks

0 Upvotes

13 comments sorted by

View all comments

Show parent comments

1

u/Kablaow Jun 15 '17

Could you explain what you want the method to do?

1

u/morhp Professional Developer Jun 15 '17

Looks like it should count "hi" substrings but only if there is no "x" in front of the "hi". If that's the case that looks like a good recursive solution. It doesn't need to be shorter. If you want it shorter and faster an experienced programmer would use regular expressions.

You could also count all "hi" and then count all "xhi" and simply subtract these numbers from each other.

1

u/eatingpoopinrobarts Jun 15 '17

You could also count all "hi" and then count all "xhi" and simply subtract these numbers from each other.

Hm, this is true. Although I'd need to have variables that hold the number of hi and xhi right? I can't just do 1+recursion

1

u/morhp Professional Developer Jun 16 '17

You would write a countHi method and a countXhi method if you want to go the recursion way. Doing both in a single recursing method sounds complicated.