I have written this method countToken that takes a Scanner s and a String t as parameters, and returns an int. It returns the number of time that t occurs as a token in s. This is as far as I can go and to me it makes sense but it doesnt work right.
public static int countToken(Scanner s, String t)
{
    int count = 0;
    while (s.hasNext()==true)
    {
        if (s.next()==t)
        {
            count++;
        }
    }
    return count;
}
 
    