模式查找器
本课属于 Coddy Java 学习旅程的“基础知识”单元。第 72 课,共 73 课。
挑战
简单编写一个程序,接收两个字符串数组作为输入,并判断第二个数组是否按连续顺序出现在第一个数组中。
当第二个数组的所有元素按相同顺序连续出现在第一个数组的某个位置时,就说明存在匹配模式,就像在字符串中查找子字符串一样。
例如:
String[] str1 = {"1", "2", "3", "4", "5", "6", "7"};
String[] str2 = {"3", "4", "5"};
// Should return trueString[] str1 = {"5", "6", "7", "8", "9"};
String[] str2 = {"6", "8"};
// Should return false (not consecutive)亲手试试
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String arrString1 = scanner.nextLine();
String arrString2 = scanner.nextLine();
String[] str1 = arrString1.split(",");
String[] str2 = arrString2.split(",");
// 在下方编写你的代码
}
}基础知识中的所有课
自己练习: Java 在线编译器