OK, so here's my assignment...ask the user for a sentence, then print each word along with its position in the sentence. Then ask for another sentence... if the sentence is empty, terminate. My code works... but I don't know how to get it to loop back to asking for another sentence. Any help is greatly appreciated.
import java.util.Scanner;
import java.util.StringTokenizer;
public class StringAssign1b {
public static void main(String[] args) {
int pos = 0;
String input;
Scanner s = new Scanner(System.in);
int count = 0;
System.out.print("Enter a sentence: ");
input = s.nextLine();
StringTokenizer str = new StringTokenizer(input);
if (!input.equals("/r/n")) {
while (str.hasMoreTokens()) {
count++;
String word = str.nextToken();
System.out.println(pos + " " + word);
pos++;
}
}
}
}