-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLabelTest.java
More file actions
30 lines (30 loc) · 1.02 KB
/
LabelTest.java
File metadata and controls
30 lines (30 loc) · 1.02 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
/*标签是为循环设计的,是为了在多重循环中方便的使用 break 和coutinue
*在循环中使用 break 或 continue 循环时跳到指定的标签处
*/
public class LabelTest {
public static void main(String[] args) {
String strSearch = "This is the string in which you have to search for a substring.";
String substring = "substring";
boolean found = false;
int max = strSearch.length() - substring.length();
testlbl:
for (int i = 0; i <= max; i++) {
int length = substring.length();
int j = i;
int k = 0;
while (length-- != 0) {
if(strSearch.charAt(j++) != substring.charAt(k++)){
continue testlbl;
}
}
found = true;
break testlbl;
}
if (found) {
System.out.println("发现子字符串。");
}
else {
System.out.println("字符串中没有发现子字符串。");
}
}
}