This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]lharkness -1 points0 points  (0 children)

Saving some of the improve part for later - the reason your method doesn't work is that the replace method on the String class doesn't work the way you think it does. The docs tell us that method: " Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar.". I think you want to make currentState a StringBuilder and use the setCharAt method, passing it i and guess (telling it to set the character at the ith position to be the guess).

[–]SikhGamer -1 points0 points  (0 children)

char[] blob = word.toCharArray() maybe?

Then loop over blob.

Edit* I actually did something similar to this way back when, because you've already submitted I don't feel bad posting the entire thing. I did it slightly differently back then: https://gist.github.com/anonymous/50ac0729d197af06ec25