-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIsSubstring.java
More file actions
34 lines (30 loc) · 844 Bytes
/
IsSubstring.java
File metadata and controls
34 lines (30 loc) · 844 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
public class IsSubstring {
public static void main(String[] args) {
evaluate("hola", "hola mundo");
evaluate("lla", "edmola");
evaluate("Dios", "Dios es Santo");
evaluate("bien", "muy bien hecho");
evaluate("hk", "hok");
evaluate("tr", "Intromisión");
evaluate("aba", "aabbaab");
}
public static void evaluate(String sub, String text) {
if(isSubstring(sub, text)) {
System.out.println("\"" + sub + "\" is substring of \"" + text + "\"");
} else {
System.out.println("\"" + sub + "\" is NOT a substring of \"" + text + "\"");
}
}
public static boolean isSubstring(String sub, String text) {
for(int t = 0, s = 0; t < text.length(); t++) {
if(text.charAt(t) == sub.charAt(s)) {
s++;
if(s == sub.length())
return true;
} else {
s = 0;
}
}
return false;
}
}