Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Java_Collections_Basic_Homework;
- import java.util.Scanner;
- public class _07_CountSubstringOccurrences {
- public static void main(String[] args) {
- Scanner reader = new Scanner(System.in);
- String input = reader.nextLine().toLowerCase();
- String sub = reader.nextLine();
- reader.close();
- int count = 0;
- int getIndex = input.indexOf(sub);
- while(input.contains(sub)){
- input = new String(
- input.substring(
- getIndex + 1, input.length()));
- getIndex = input.indexOf(sub);
- count++;
- }
- System.out.println(count);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment