How can I make it so that the program will print the number of words in a sentence?
<p>I can already count vowels, consonants, spaces, and special characters.
I have to do it using some beginner techniques. [EDIT:  given that last statement and the following code, this question sounds like help for homework]  Nothing too complicated. </p>

<pre><code>import java.util.Scanner;

 public class JBlahBlah
 {
static Scanner sc = new Scanner(System.in                                                      );

public static void main(String[] Theory)
{

    JWaffles MyWaffles = new JWaffles();

    MyWaffles.ProgramHeading();

    System.out.println("Enter a string:"                                                       );
    String SentenceContents = sc.nextLine(                                                     );

    int VowelCount = 0,ConsonantCount = 0,WordCount = 0,SpaceCount = 0,SpecialCharCount = 0     ;

    for (int Bat = 0; Bat &lt; SentenceContents.length(); Bat++)
    {
        char Vowels = SentenceContents.charAt(Bat         );
        if (      (Vowels == 'A') || (Vowels == 'a'       )
               || (Vowels == 'E') || (Vowels == 'e'       )
               || (Vowels == 'I') || (Vowels == 'i'       )
               || (Vowels == 'O') || (Vowels == 'o'       )
               || (Vowels == 'U') || (Vowels == 'u'      ))
        VowelCount++;

        char Consonants = SentenceContents.charAt(Bat);
        if (      (Consonants == 'B') || (Consonants == 'b')
               || (Consonants == 'C') || (Consonants == 'c')
               || (Consonants == 'D') || (Consonants == 'd')
               || (Consonants == 'F') || (Consonants == 'f')
               || (Consonants == 'G') || (Consonants == 'g')
               || (Consonants == 'H') || (Consonants == 'h')
               || (Consonants == 'J') || (Consonants == 'j')
               || (Consonants == 'K') || (Consonants == 'k')
               || (Consonants == 'L') || (Consonants == 'l')
               || (Consonants == 'M') || (Consonants == 'm')
               || (Consonants == 'N') || (Consonants == 'n')
               || (Consonants == 'P') || (Consonants == 'p')
               || (Consonants == 'Q') || (Consonants == 'q')
               || (Consonants == 'R') || (Consonants == 'r')
               || (Consonants == 'S') || (Consonants == 's')
               || (Consonants == 'T') || (Consonants == 't')
               || (Consonants == 'V') || (Consonants == 'v')
               || (Consonants == 'W') || (Consonants == 'w')
               || (Consonants == 'X') || (Consonants == 'x')
               || (Consonants == 'Y') || (Consonants == 'y')
               || (Consonants == 'Z') || (Consonants == 'z') )

        ConsonantCount++;

        char Spaces = SentenceContents.charAt(Bat);
                    if ( (Spaces == ' ') )

        SpaceCount++;

        char SpecialCharacters = SentenceContents.charAt(Bat);
                    if (      (SpecialCharacters == '!') || (SpecialCharacters == '@'   )
                           || (SpecialCharacters == '#') || (SpecialCharacters == '$'   )
                           || (SpecialCharacters == '%') || (SpecialCharacters == '^'   )
                           || (SpecialCharacters == '&amp;') || (SpecialCharacters == '*'   )
                           || (SpecialCharacters == '(') || (SpecialCharacters == ')'   )
                           || (SpecialCharacters == '-') || (SpecialCharacters == '_'   )
                           || (SpecialCharacters == '+') || (SpecialCharacters == '='   )
                           || (SpecialCharacters == ',') || (SpecialCharacters == '&lt;'   )
                           || (SpecialCharacters == '.') || (SpecialCharacters == '&gt;'   )
                           || (SpecialCharacters == '?') || (SpecialCharacters == '/'   )
                           || (SpecialCharacters == '"') || (SpecialCharacters == ';'   )
                           || (SpecialCharacters == ':') || (SpecialCharacters == '{'   )
                           || (SpecialCharacters == '[') || (SpecialCharacters == '}'   )
                           || (SpecialCharacters == ']') || (SpecialCharacters == '~'   )
                           || (SpecialCharacters == '`') || ((SpecialCharacters == '1'  )
                           || (SpecialCharacters == '2') || (SpecialCharacters == '3'   )
                           || (SpecialCharacters == '4') || (SpecialCharacters == '5'   )
                           || (SpecialCharacters == '6') || (SpecialCharacters == '7'   )
                           || (SpecialCharacters == '8') || (SpecialCharacters == '9'   )
                           || (SpecialCharacters == '|')                               ))

        SpecialCharCount++;
    }
    System.out.println("There are " + VowelCount + " vowels in this sentance"                  );
    System.out.println("There are " + ConsonantCount + " consonants in this sentance"          );
    System.out.println("There are " + SpaceCount + " spaces in this sentance"                  );
    System.out.println("There are " + SpecialCharCount + " special characters in this sentance");

}
}
</code></pre>

<p>How can I make it so that the program will print the number of words? What if their are several spaces in between the words?</p>
