There is a good way of doing it. I will give you the agorithm

1. you take an input string from the user lets say word
2. then you can use the lo statement
while(word.charAt(3) != ' ' &&...