Pattern Finder
Part of the Fundamentals section of Coddy's Java journey — lesson 72 of 73.
Challenge
EasyCreate a program that receives two arrays of strings as input and determines if the second array appears as a pattern within the first array (in consecutive order).
A pattern exists when all elements of the second array appear together, in the same order, somewhere within the first array, like finding a substring within a string.
For example:
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)Try it yourself
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(",");
// Write your code below
}
}All lessons in Fundamentals
4Operators Part 1
Arithmetic OperatorsModulo OperatorIncrement/DecrementPost Increment/DecrementArithmetic ShortcutsComparison OperatorsString Comparison5Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3Logical Operators Part 43Variables Part 2
ConstantsNaming ConventionsRecap - Initialize VariablesType Casting Part 1Type Casting Part 26Decision Making
If StatementIf - ElseSwitch StatementTernary OperatorRecap - If ElseNested If - Else