Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class CountAllWords {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- String input = scan.nextLine();
- int wordCount = 0;
- String[] words = input.split("\\W+");
- for (String word : words) {
- wordCount++;
- }
- System.out.println(wordCount);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement