AlexKondov

Java Count Specific Words

May 22nd, 2014
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.43 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class CountSpecifiedWord {
  5.  
  6.     public static void main(String[] args) {
  7.         Scanner in = new Scanner(System.in);
  8.         String input = in.nextLine();
  9.         String[] words = input.split("\\W+");
  10.         String word = in.next();
  11.         int count = 0;
  12.        
  13.         for (String string : words) {
  14.             string = string.toLowerCase();
  15.             if (string.equals(word)) {
  16.                 count++;
  17.             }
  18.         }
  19.         System.out.println(count);
  20.     }
  21.  
  22. }
Advertisement
Add Comment
Please, Sign In to add comment