Advertisement
coasterka

#4CountAllWords

Jun 3rd, 2014
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.35 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class CountAllWords {
  4.  
  5.     public static void main(String[] args) {
  6.        
  7.         Scanner scan = new Scanner(System.in);
  8.         String input = scan.nextLine();    
  9.         int wordCount = 0;
  10.         String[] words = input.split("\\W+");
  11.        
  12.         for (String word : words) {
  13.             wordCount++;   
  14.         }          
  15.        
  16.         System.out.println(wordCount);
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement