AlexKondov

Java Count Substracting Occurances

May 22nd, 2014
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.47 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class CountSubstringOccurances {
  5.  
  6.     public static void main(String[] args) {
  7.         Scanner in = new Scanner(System.in);
  8.         String sentence = in.nextLine().toLowerCase();
  9.         String word = in.nextLine().toLowerCase();
  10.         int counter = 0;
  11.  
  12.         for (int i = 0; i <= sentence.length() - word.length(); i++) {
  13.             if (sentence.substring(0 + i, word.length() + i).contains(word)) {
  14.                 counter++;
  15.             }
  16.         }
  17.         System.out.println(counter);
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment