Advertisement
Guest User

Untitled

a guest
Dec 13th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.60 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class CuentaPalabras
  4. {
  5.     public static void main( String [] args)
  6.     {
  7.         Scanner input = new Scanner( System.in ).useLocale( Locale.US );  
  8.         int countWord = 0;
  9.         int countLine = 0;
  10.         while( input.hasNextLine() ) {
  11.             String line = input.nextLine();
  12.             Scanner word = new Scanner ( line );
  13.             while( word.hasNext() ){
  14.                 word.next();
  15.                 countWord ++;
  16.             }
  17.             countLine ++;
  18.         }
  19.         System.out.printf("%d words %n %d lines", countWord, countLine );
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement