Scanner class has the methods hasNext(), hasNextInt(), hasNextBoolean(). So in the first while loop it is only checking s1 i.e s1.hasNext() and concatenating s in hits variable every time this loop is run. In the next while loop it is checking s2 i.e. s2.hasNext() and within that loop it is checking s2.hasNextInt() or s2.hasNextBoolean() in if and is accordingly concatenating "i", "b" & "s2" in hits. Remember there are variables b and b2 declared as boolean but what you are concatenating in hits are strings "s", "b", "i" and not the values in variable. Try to understand the flow and I hope this clears your doubt.
Asmita