import java.util.Scanner; public class Words { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter a phrase: "); String phrase = input.nextLine(); int count = countWords(phrase); System.out.println("There are " + count + " words in the phrase."); Scanner words = new Scanner(phrase); while (words.hasNext()) { String word = words.next(); System.out.println(word); } System.out.println(phrase); } public static int countWords(String p) { Scanner words = new Scanner(p); int count = 0; while (words.hasNext()) { String nextOne = words.next(); count++; System.out.println("Word #" + count + ": " + nextOne); } return count; } }