Java 实例 - continue 关键字用法
Java 教程
· 2019-02-10 16:58:41
Java continue 语句语句用来结束当前循环,并进入下一次循环,即仅仅这一次循环结束了,不是所有循环结束了,后边的循环依旧进行。
以下实例使用了 continue 关键字来跳过当前循环并开始下一次循环:
Main.java 文件
public class Main {
public static void main(String[] args) {
StringBuffer searchstr = new StringBuffer("hello how are you. ");
int length = searchstr.length();
int count = 0;
for (int i = 0; i < length; i++) {
if (searchstr.charAt(i) != 'h')
continue;
count++;
searchstr.setCharAt(i, 'h');
}
System.out.println("发现 " + count
+ " 个 h 字符");
System.out.println(searchstr);
}
}
以上代码运行输出结果为:
发现 2 个 h 字符 hello how are you.
点击查看所有 Java 教程 文章: https://codercto.com/courses/l/12.html
XML Hacks
Michael Fitzgerald / O'Reilly Media, Inc. / 2004-07-27 / USD 24.95
Developers and system administrators alike are uncovering the true power of XML, the Extensible Markup Language that enables data to be sent over the Internet from one computer platform to another or ......一起来看看 《XML Hacks》 这本书的介绍吧!
JSON 在线解析
在线 JSON 格式化工具
HTML 编码/解码
HTML 编码/解码