forked from ayushi18103104/javaASSIGNMENTS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment1 - Question 1.java
More file actions
29 lines (27 loc) · 959 Bytes
/
Copy pathAssignment1 - Question 1.java
File metadata and controls
29 lines (27 loc) · 959 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
27
28
29
import java.util.Scanner;
class solution {
static int count(String pattern, String text) {
int psize = pattern.length();
int tsize = text.length();
int res = 0;
for (int i = 0; i <= tsize - psize; i++) {
int j;
for (j = 0; j < psize; j++) {
if (text.charAt(i + j) != pattern.charAt(j)) {
break;
}
}
if (j == psize) {
res++;
j = 0;
}
}
return res;
}
static public void main(String[] args) {
Scanner sc= new Scanner(System.in);
String txt = sc.nextLine();
String pat = sc.nextLine();
System.out.println(count(pat, txt));
}
}