forked from AdityaShaw1/Competitive-Coding-Using-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubstring_Matching_Java
More file actions
43 lines (35 loc) · 774 Bytes
/
Copy pathSubstring_Matching_Java
File metadata and controls
43 lines (35 loc) · 774 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import java.util.*;
public class Main {
static boolean checkPattern(String str1, String str2 ){
int i,j;
int n=str1.length();
int m=str2.length();
boolean flag=true;
if(n>=m){
for( i=0;i<n;i++)
{
if(str1.charAt(i)==str2.charAt(0))
{
for( j=0;j<m;j++)
{
if(str1.charAt(i+j)!=str2.charAt(j))
break;
}
if(j==m)
return true;
}
}
}
return false;
}
public static void main(String[] args) {
Scanner ob = new Scanner(System.in);
String str1 = ob.nextLine();
String str2 = ob.nextLine();
boolean f = checkPattern(str1,str2);
if(f==true)
System.out.println("Matched");
else
System.out.println("Not Matched");
}
}