如何查看字符串数组的元素是否包含某个字母?我需要它来做刽子手。使用的单词数组是 Words。continueGame() 是我放这个的地方。我想我可以得到我的随机词,然后找出这个字母是否在那个随机词中。我怎么做?
public void continueGame(){
letterSelected = JOptionPane.showInputDialog(null, "Take another guess!");
if(getWords().indexOf(getWords()) == (letterSelected)){
}
if(! getWords().contains(letterSelected)){
guesses++;
continueGame();
}else{
System.out.println(letterSelected);
}
checkBodyParts();
JOptionPane.showInputDialog(null, "");
}
#
/**Get the random word from the array*/
public String getWords (){
String randomWord = words[randy.nextInt( words.length)];
return randomWord;
}
/**Get the indexes of the letter of the random word indices don't start with 1*/
public String getSelected(){
return letterSelected;
}
/**Finds index of the letter of randomWord*/
public int getIndex(){
int index = getWords().indexOf(getSelected());
return index;
}