Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- class Naive_string{
- public static void main(String[] args){
- Scanner sc = new Scanner(System.in);
- System.out.println("Enter the first string");
- String a = sc.nextLine();
- int l1 = a.length();
- System.out.println("Enter the second string");
- String b = sc.nextLine();
- int l2 = b.length();
- int y = 0;
- for(int x = 0; x<=l1-l2; x++){
- for(y = 0; y< l2; y++){
- if (a.charAt(x + y) != b.charAt(y))
- break;
- }
- if (y == l2){
- System.out.println("Shift at "+ x);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment