Advertisement
DNNdrago

6. Count Specified Word

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