Advertisement
YankoZlatanov

Untitled

Feb 10th, 2015
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.55 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class CountSpecifiedWord {
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         Scanner input = new Scanner(System.in);
  8.  
  9.         String text = "";
  10.  
  11.    
  12.             text += input.nextLine().toLowerCase();
  13.  
  14.            
  15.        
  16.         String[] countWords = text.split("[^a-zA-Z0-9']+");
  17.         int count = 0;
  18.        
  19.         String check = input.nextLine().toLowerCase();
  20.         for (String string : countWords) {
  21.  
  22.             if (!string.equals(" ") && !string.equals("")) {
  23.                 if (string.equals(check)) {
  24.                     count++;
  25.                 }
  26.             }
  27.         }
  28.         System.out.println(count);
  29.     }
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement