I need to following program to output whatever string is input with each word on a new line and to count the total words. This so far outputs each letter on a new line. I used text.split to count the words and tried to add this into my for loop but it won't work, maybe because the for loop is Integer but I can't find how to add this in.
public class TextTest {
public static void main(String[] args) {
String text = Input.getString("Text: ");
String[] separated = text.split(" ");//separates by spaces
do {
if (text.isEmpty()) {
System.out.println("empty text");
} else {
for (Integer position = 0; position < text.length(); position++) {
System.out.println(text.charAt(position));
}
}
int WordCount = separated.length;
System.out.println("number of words: " + WordCount);
} while (Repeat.repeat());