Advertisement
Masovski

[Java Basics][Collections-HW] 07. Count Substr Occurrences

May 24th, 2014
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.45 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class CountSubstringOccurrences {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner sc = new Scanner(System.in);
  7.        
  8.         String input = sc.nextLine().toLowerCase();
  9.         String word = sc.nextLine().toLowerCase();
  10.        
  11.         int count = 0;
  12.             int index = 0;
  13.               while ((index = input.indexOf(word, index)) != -1) {
  14.               count++;
  15.               index++;
  16.             }
  17.             System.out.println(count);
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement