Hello! I'm suppose to code a word counter for my Java class.
The user is suppose to keep entering a sentence until they type "xxx" then at the end, it'd count how many words entered.

It's only counting the "xxx" for me, so at the end, it says I only entered 1 word. Can I get some pointers on how to fix this?

Here's my code:

import java.util.Scanner;
import java.util.StringTokenizer;

public class WordCounter
	public static void main(String[]args)
		Scanner keyboard = new Scanner(System.in);
		String speech;
			System.out.println("Enter your speech: ");
			speech = keyboard.nextLine();

		int counter=0;
		StringTokenizer st = new StringTokenizer(speech);
		System.out.println("\nThere are " + counter + " words in the speech.");



This question has already been answered. Start a new discussion instead.