集册 Java实例教程 继续标签演示

继续标签演示

欢马劈雪     最近更新时间:2020-01-02 10:19:05

580
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
继续标签演示

class ContinueWithLabelDemo {

    public static void main(String[] args) {
/* 来自 时代Java公众号*/

        String searchMe = "Look for a substring in me";

        String substring = "sub";

        boolean foundIt = false;


        int max = searchMe.length() - substring.length();


        test: for (int i = 0; i <= max; i++) {

            int n = substring.length();

            int j = i;

            int k = 0;

            while (n-- != 0) {
            /**
            时 代 J     a    v  a - nowjava.com 提供 
            **/

                if (searchMe.charAt(j++) != substring.charAt(k++)) {

                    continue test;

                }

            }

            foundIt = true;

            break test;

        }

        System.out.println(foundIt ? "Found it" : "Didn't find it");

    }

}


展开阅读全文