-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathprog16.java
42 lines (34 loc) · 1 KB
/
prog16.java
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
package chap3;
import java.util.Scanner;
public class prog16 {
public static boolean contains(String s1,String s2)
{
boolean f = false;
for (int i = 0; i < s2.length() - 1; i++)
{
if (s2.charAt(i) == s1.charAt(0))
{
for (int j = 0; j < s1.length(); j++)
{
if ((i + j) < s2.length() && s1.charAt(j) == s2.charAt(i + j) && j == s1.length() - 1)
{
f = true;
break;
}
}
}
}
return f;
}
public static void main(String[] args)
{
// TODO Auto-generated method stub
Scanner sc = new Scanner (System.in);
String s1,s2;
System.out.println("enter the first string :");
s1 = sc.nextLine();
System.out.println("enter the second string :");
s2 = sc.nextLine();
System.out.println("If the second string contains the first one? "+contains(s1, s2));
}
}