-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathContainsSubstring.java
More file actions
39 lines (31 loc) · 1.03 KB
/
ContainsSubstring.java
File metadata and controls
39 lines (31 loc) · 1.03 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
class containsSubstring {
public static void main(String[] args) {
System.out.println();
System.out.println("false");
System.out.println();
System.out.println("Error");
System.out.println();
String word = "Hamburg";
String substring = "burg";
System.out.println(containsSubstring(word, substring));
}
public static boolean containsSubstring(String word, String substring) {
boolean containsSubstring = false;
for (int i = 0; i < word.length(); i++) {
for (int j = 0; j < substring.length(); j++) {
if (i + j > word.length()) {
break;
}
if (word.charAt(i + j) != substring.charAt(j)) {
break;
} else {
if (j == substring.length() - 1) {
containsSubstring = true;
break;
}
}
}
}
return containsSubstring;
}
}