Home > Java > javaTutorial > Java Example - Label

Java Example - Label

黄舟
Release: 2017-02-16 10:24:30
Original
1171 people have browsed it

The tags in Java are designed for loops to facilitate the use of break and coutinue in multiple loops.

The following example jumps to the specified label when using break or continue loops in the loop:

/*
 author by w3cschool.cc
 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("字符串中没有发现子字符串。");
      }
   }}
Copy after login

The output result of the above code is:

发现子字符串。
Copy after login

The above is the content of Java Example-Label. For more related content, please pay attention to the PHP Chinese website (m.sbmmt.com)!


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