Home > Java > javaTutorial > body text

Java Example - continue keyword usage

黄舟
Release: 2017-02-16 10:19:27
Original
1365 people have browsed it

Java continue statement is used to end the current loop and enter the next loop. That is, only this loop ends, not all loops end, and subsequent loops still proceed.

The following example uses the continue keyword to skip the current loop and start the next loop:

/*
 author by w3cschool.cc
 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) != &#39;h&#39;)
         continue;
         count++;
         searchstr.setCharAt(i, &#39;h&#39;);
      }
      System.out.println("发现 " + count 
      + " 个 h 字符");
      System.out.println(searchstr);
   }}
Copy after login

The output result of running the above code is:

发现 2 个 h 字符
hello how are you.
Copy after login

The above is the Java example - For information on the usage of the continue keyword, please pay attention to the PHP Chinese website (www.php.cn) for more related content!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!