1

I'm asking for help in implementing this.

Example:

User input : The student is studying

Correct answer: The student went home

Output like this:

Is there any algorithm for that can do this task? Is it possible to divide the sentence into words, store it in an array and compare it?

Onik
  • 19,396
  • 14
  • 68
  • 91
Mark
  • 45
  • 6
  • use `split` and a regluar expression, like [this](http://stackoverflow.com/questions/4674850/converting-a-sentence-string-to-a-string-array-of-words-in-java) – peguerosdc Dec 27 '14 at 09:13

1 Answers1

3

Store the user input (from prompt, textbox, or any other input fields) to the variable. Store the correct answer into another variable.

Convert the two variables into array consisting each word in a sentence. (As what peguerosdc said)

Make a loop that ends at the last index of the array of the inputted word. This loop let the two words from the inputted sentence and the correct sentence be compared and it shall make the color of the word to blue if it is matched and red for not.

Sample code:

for (int i=0; i<words.length;i++) // loop until the end of the word
{
if(word[i]==correctWord[i]) // compare the word from user input to the word of correct sentence
{
// color it blue
}
else
{
// color it red
}
}
Mai
  • 363
  • 3
  • 16
  • hello!I'm having a problem in displaying the sentence, my code only shows the last word of the sentence which is studying. Please help me with this. How can I store the words with its corresponding color in an array then display them altogether?Sorry for the late reply – Mark Jan 01 '15 at 13:16
  • Did you actually use javascript? You mentioned android and none of your tags is a javascript. The sample code I provided in my answer is a javascript. – Mai Jan 01 '15 at 13:43
  • You asked the algorithm for that problem so I answered your question by word. @Mark – Mai Jan 01 '15 at 13:55
  • Yes I used your code. Anyway thanks for your help. I somehow got the target output. :) – Mark Jan 04 '15 at 05:04