Jacob_Thomas

Naive String

Jan 28th, 2021
442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.69 KB | None | 0 0
  1. import java.util.*;
  2. class Naive_string{
  3.     public static void main(String[] args){
  4.         Scanner sc = new Scanner(System.in);
  5.         System.out.println("Enter the first string");
  6.         String a = sc.nextLine();
  7.         int l1 = a.length();
  8.         System.out.println("Enter the second string");
  9.         String b = sc.nextLine();
  10.         int l2 = b.length();
  11.         int y = 0;
  12.         for(int x = 0; x<=l1-l2; x++){
  13.             for(y = 0; y< l2; y++){
  14.                 if (a.charAt(x + y) != b.charAt(y))
  15.                     break;
  16.             }
  17.             if (y == l2){
  18.                 System.out.println("Shift at "+ x);
  19.             }
  20.         }
  21.        
  22.        
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment