I have one method with one letter(string\char?) as argument and one word active at a time. I would like to see if this one letter, is in the word which is active at the time.
That could probably have been explained better. Maybe code will do the trick:
public void checkLetter(String letter){
for(int i = 0; i<activeWord.length(); i++){
if(letter.equals(activeWord.[i])){
// Run a method which gives the user a correct letter pushed.
}
else {
String failed = "Could not find the letter in the active word.";
// Run a method which gives the user one wrong letter pushed.
}
}
}
So, this is going to be a hangman game for android i’m making for fun. Right now i have images as letters. When the letter(image) is pressed, this method runs, and the letter pushed will be the argument.
Does anyone have any good ideas how i can find out if the letter is in the word, and which posistion it is in?
I would love some help 🙂
EDIT: Btw, the current code returns int every time ofc, cause the [i] is an int. This is where im strugling to get the code to return a string. Do i have to split the word up into letter before i can equal them to another string?
Thanks.
use String’s methods