Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // wrapper class to split the input into an array and then check the number of words based on the array.length
- System.out.println("Input a sentence to get a word count: ");
- userInput = keyboard.nextLine();
- String[] sentence = userInput.split(" ");
- System.out.printf("There are %s words in that sentence.", sentence.length);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement