Skip to content

Instantly share code, notes, and snippets.

@CompSciRocks
Last active April 23, 2019 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CompSciRocks/6cf51a409b5cc7561d162a6029a960a2 to your computer and use it in GitHub Desktop.
Save CompSciRocks/6cf51a409b5cc7561d162a6029a960a2 to your computer and use it in GitHub Desktop.
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