continuewithlabel.java
来自「java程序设计 清华出版社 孙燮华老师编写的程序源代码」· Java 代码 · 共 26 行
JAVA
26 行
//ContinueWithLabel.java
public class ContinueWithLabel{
public static void main(String[] args){
String search = "Look for a substring in me";
String substring = "sub";
boolean foundIt = false;
int max = search.length()-substring.length();
test:
for(int i = 0;i<=max;i++){
int j = i, k = 0, n = substring.length();
while (n-- != 0) {
if(search.charAt(j++) != substring.charAt(k++)){
continue test; //跳到test所标识的for循环继续进行
}
}
foundIt = true;
break test;
}
System.out.println(foundIt ? "Found it": "Didn't find it");
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?