Java 实例 - 标签(Label)

Java 教程 · 2019-02-10 17:12:32

Java 中的标签是为循环设计的,是为了在多重循环中方便的使用break 和coutinue 。

以下实例当在循环中使用 break 或 continue 循环时跳到指定的标签处:

Main.java 文件

public class Main { 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("字符串中没有发现子字符串。"); } } }

以上代码运行输出结果为:

发现子字符串。

点击查看所有 Java 教程 文章: https://www.codercto.com/courses/l/12.html

查看所有标签

数学世纪

数学世纪

皮耶尔乔治·奥迪弗雷迪 / 胡作玄、胡俊美、于金青 / 上海科学技术出版社 / 2012-1 / 28.00元

《数学世纪:过去100年间30个重大问题》以简短可读的方式论述了整个20世纪的数学。20世纪的数学博大精深,新兴领域及学科的建立发展,许多经典问题得到解决,大量新的有意义的问题的引入,为数学带来了活力。《数学世纪:过去100年间30个重大问题》介绍了数学基础,20世纪的纯粹数学、应用和计算数学,以及目前未解的重要问题,中间穿插了希尔伯特的23个问题的解决情况、菲尔兹奖和沃尔夫奖得主的工作成就等。一起来看看 《数学世纪》 这本书的介绍吧!

URL 编码/解码
URL 编码/解码

URL 编码/解码

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试