Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Problem_07_CountSubstringOccurrences {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String text = scanner.nextLine();
- String searchedString = scanner.nextLine();
- int stringCounter = 0;
- int stringIndex = (text.toLowerCase().indexOf(searchedString.toLowerCase()));
- while (stringIndex != -1){
- stringCounter++;
- stringIndex = (text.toLowerCase().indexOf(searchedString.toLowerCase(),stringIndex+1));
- }
- System.out.println(stringCounter);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement