<commit_before>/*
  Write a program that prompts the user to enter two strings and tests whether
  the second string is a substring of the first string.
*/

import java.util.Scanner;

public class E22_03 {
  public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    System.out.print("Enter a string s1: ");
    String s1 = input.nextLine();
    System.out.print("Enter a string s2: ");
    String s2 = input.nextLine();

    int index = 0;
    int matchIndex = -1;
    for (int i = 0; i < s1.length(); i++) {
      char c1 = s1.charAt(i);
      char c2 = s2.charAt(index);
      if (c1 == c2) {
        index++;
        if (index == s2.length()) {
          matchIndex = i - (index - 1);
          break;
        }
      } else {
        index = 0;<commit_msg>Add to problem description<commit_after>/*
  Write a program that prompts the user to enter two strings and tests whether
  the second string is a substring of the first string. Suppose the neighboring
  characters in the string are distinct. (Don't use the indexOf method in the
  String class.) Your algorithm needs to be at least O(n) time.
*/

import java.util.Scanner;

public class E22_03 {
  public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    System.out.print("Enter a string s1: ");
    String s1 = input.nextLine();
    System.out.print("Enter a string s2: ");
    String s2 = input.nextLine();

    int index = 0;
    int matchIndex = -1;
    for (int i = 0; i < s1.length(); i++) {
      char c1 = s1.charAt(i);
      char c2 = s2.charAt(index);
      if (c1 == c2) {
        index++;
        if (index == s2.length()) {
          matchIndex = i - (index - 1);
          break;
        }
      } else {
        index = 0;
{'fraction_non_alphanumeric': 0.12152186257808063, 'fraction_numerical': 0.02385008517887564, 'mean_word_length': 2.299625468164794, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5246911', 'n_tokens_mistral': 578, 'n_tokens_neox': 559, 'n_words': 203}