While indexOf(the) in java gives me number of characters preceding “the” in the sentence One day I saw the beautiful bird, I would like to know the way of getting the number of words preceding it. For example, the output for the given sentence would be 4!
Thank you.
Have a look at java.util.Scanner
Scan and count the words until you hit the
EDIT: very simple example (and not tested 😉