자바·파이썬·자바스크립트/Java 프로그래밍

자바 continue with label 예제

바로이순간 2011. 12. 11. 03:39

/*
  Java continue with label example.
*/
import java.io.*;
class ContinueWithLabelDemo {
    public static void main(String[] args) {

        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) {
                if (searchMe.charAt(j++)
                        != substring.charAt(k++)) {
                    continue test;
                }
            }
            foundIt = true;
                 break test;
        }
        System.out.println(foundIt ? "Found it" :
                                     "Didn't find it");
    }
}

=========================================================================
Here is the output from this program.

     Found it

'자바·파이썬·자바스크립트 > Java 프로그래밍' 카테고리의 다른 글

cmd창 사용하기  (0) 2012.03.12
자바 삭제법  (0) 2012.02.19
초보자 문제  (0) 2011.12.16
자바 continue 예제  (0) 2011.12.11
주소가 있는 break  (0) 2011.12.11