Masovski

[Java Basics][Collections-HW] 06. Count Specified Word

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