I take the intro class for Java, and we have a project that deals with the executioner game. I have most of the code, but there is an error that I cannot solve.
First, the program asks the user for a letter and one space in which they think that the letter is coming, then the program displays the word in a series of hyphens and, if the user makes the correct assumption, the letter in the corresponding hyphen is replaced by the letter.
For testing purposes, the default word was narrow.
So, if I guessed the letter rand for the space, I had to guess the index 2, the program would give me:
Guess a letter: r
Guess a space: 2
Guess: --r---
The problem I am facing is that when I guess the index 3 for a space and try to guess the next r, the program just gives me the same result as before.
We are not allowed to use arrays or a string builder because we have not talked about them yet.
Here are my variables:
String blank = "narrow";
String start = "";
String end = "";
String word = "";
String input;
String space = "";
String guess = "";
Here is the code that the string manipulates.
for (int i = 0; i < blank.length(); i++) {
if (i == blank.indexOf(input)) {
start = guess.substring(0, i);
end = guess.substring(i + 1);
word = start.concat(input).concat(end);
}
}
I think this is due to if statement, but I tried some other things and they did not work. Any help would be appreciated.
Thank.