I am trying to write a program that reads an inputted sentence and takes each word an puts them on a separate line. Then the program needs to count the number of words. I really do suck at this and am only still in this class because I have to take continue to be a Math major. Any help is greatly appreciated :)
here is it so far. The compiler is telling me it expects ")" in the last line. I have no idea why. Again...I suck at this.
import java.util.Scanner;
public class Sentence_count
{
public static void main (String [] args)
{
Scanner keyboard = new Scanner (System.in);
System.out.println ("Enter a single line of text with words separated by a single space");
String text = keyboard.next();
int numwords = 0;
int index = text.indexOf(' ');
while (index != 1);
{
numwords++;
String word = text.substring (0, index);
System.out.println (word);
text = text.substring (index + 1).trim();
index = text.indexOf(' ');
}
System.out.println (+text);
System.out.println ("There are " +numwords " in your sentence.");
}
}