Skip to content

Commit 0c667ad

Browse files
committed
containsSubstring
1 parent 94a0e82 commit 0c667ad

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Strings/containsSubstring.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
3+
program to find if a substring is part of a string and also print the index from which it starts
4+
5+
*/
6+
7+
package Strings;
8+
9+
public class containsSubstring {
10+
11+
public static void main (String[]args) {
12+
13+
check("acknowledge","now");
14+
15+
}
16+
17+
public static void check(String str,String toS) {
18+
19+
str=str.toUpperCase();
20+
toS=toS.toUpperCase();
21+
22+
int index=-1;
23+
index=str.indexOf(toS);
24+
25+
if (index!=-1)
26+
System.out.println("substring found , starts at : "+index);
27+
else
28+
System.out.println("substring not found");
29+
30+
}
31+
32+
}

0 commit comments

Comments
 (0)