-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubinside.java
More file actions
41 lines (37 loc) · 744 Bytes
/
Copy pathSubinside.java
File metadata and controls
41 lines (37 loc) · 744 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
import java.io.*;
import java.util.*;
public class Subinside
{
Public Static void main (String [] args)
{
String s1 = "abcde";
String s2 = "cd";
int index = -1;
int count = 0;
for ( int i=0; i<s1.length;i++)
{
if (s1.charAt(i)==s2.charAt(0) && count == 0)
{
index = i;
count++;
}
else if ( s1.charAt(i) == s2.charAt(0))
{
count++;
}
else
{
index = -1;
count = 0;
}
if (count == s2.length())
{
break;
}
}
if ( index > 1)
System.out.println (" Matched at index" +index);
else
System.out.println (" S2 string is not a sub string of S1");
}
}