Guest User

Untitled

a guest
Feb 4th, 2015
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4.  
  5. public class Problem05CountWords {
  6.     public static void main(String[] args) {
  7.  
  8.         BufferedReader input = new BufferedReader(new InputStreamReader(
  9.                 System.in));
  10.         String line;
  11.         int count = 0;
  12.         try {
  13.             while ((line = input.readLine()) != null && line.length() != 0) {
  14.                 String[] words = line.split("\\W+");
  15.                 count += words.length;
  16.             }
  17.         } catch (IOException e) {
  18.  
  19.             System.out.println("Tegav si brat");
  20.         }
  21.         System.out.println(count);
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment