Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Solution for HiddenWord Free Response - https://compsci.rocks/hiddenword-solution/
public class HiddenWord {
private String word;
public HiddenWord(String w) {
word = w;
}
public String getHint(String guess) {
String out = "";
for (int i=0; i<guess.length(); i++) {
String guessCharacter = guess.substring(i, i+1);
String wordCharacter = word.substring(i, i+1);
if (guessCharacter.equals(wordCharacter)) {
out += guessCharacter;
}
else if (word.indexOf(guessCharacter) >= 0) {
out += "+";
}
else {
out += "*";
}
}
return out;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment