编辑代码

/*04 张浩宇*/
class Main {
	public static void main(String[] args) {
        String source = "I am Tom, I am from China";
        String target = "Tom";

        char[] sourceCharArray = source.toCharArray();
        char[] targetCharArray = target.toCharArray();
        boolean matched = false;
        for (int i = 0; i <= sourceCharArray.length - targetCharArray.length; i ++) {
            if (target.isEmpty()) matched = true;
            if (matched) break;
            for (int j = 0; j < targetCharArray.length; j ++) {
                if (sourceCharArray[i + j] == targetCharArray[j]) {
                    if (j == targetCharArray.length - 1) matched = true;
                } else break;
            }
        }
        String result = "\"" + target + "\"";
        if (matched) result += " 在 "; else result += " 不在 ";
        result += "\"" + source + "\"" + " 中出现。";
        System.out.println(result);
    }
}