-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCountSubstring.java
More file actions
26 lines (18 loc) · 593 Bytes
/
CountSubstring.java
File metadata and controls
26 lines (18 loc) · 593 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package CountSubstricOcc;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class CountSubstring {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String text = scanner.nextLine().toLowerCase();
String word = scanner.nextLine().toLowerCase();
Pattern pattern = Pattern.compile(word);
Matcher matcher = pattern.matcher(text);
int counter = 0;
while(matcher.find()){
counter++;
}
System.out.println(counter);
}
}