I have a code here that changes the color of a word from a sentence. Violet if the word found is of the same position. Yellow if the answer contains a word but of a different position and red if the word is not found.
My problem right now is that the color changes to violet even though the word is of different position. I also tried to use splitInput[i].contains(splitAnswer[i]) to change the word to yellow but i got a repeated words for example "It was a a sample sample sentence sentence".
String answer = "This is a sample sentence"
String userInput = "It was a sample sentence"
boolean wordFound = false;
String[] splitAnswer = answer.split(" ");
String[] splitInput = userInput.split(" ");
for (int i=0; i<splitAnswer.length;i++)
{
for (int j=0;j<splitInput.length;j++)
{
if(splitInput[i].equalsIgnoreCase(splitAnswer[i]))
{
wordFound = true;
//color the word to violet
}
{
if(wordFound==false)
{
//color the word to red
}
//display the sentence
wordFound == false;
}