-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsubstring.java
More file actions
47 lines (45 loc) · 1.22 KB
/
substring.java
File metadata and controls
47 lines (45 loc) · 1.22 KB
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
44
45
46
47
//5.C Program to Check if the Substring is present in the given String
import java.util.*;
class substring
{
public static void main(String arr[])
{
Scanner sc=new Scanner(System.in);
System.out.println("\nEnter the String ");
StringBuffer str=new StringBuffer(sc.nextLine());
//System.out.println(str);
System.out.println("\nEnter the Substring you want to find");
StringBuffer s=new StringBuffer(sc.nextLine());
int l=s.length();
int count=0;
int j=0;
int ok=0;
for(int i=0;i<str.length();i++)
{
if(ok==1)
{
break;
}
if(str.charAt(i)==s.charAt(j))
{
count++;
j++;
if(count==l)
{
System.out.println("Substring is present");
ok=1;
break;
}
}
else
{
count=0;
j=0;
}
}
if(ok==0)
{
System.out.println("Substriong is NOT present");
}
}
}