Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.lang.*;
- class occurs
- {
- public static void main(String args[])
- {
- Scanner t = new Scanner (System.in);
- System.out.println("enter 1st string");
- String s1 = t.next();
- int n1 = s1.length();
- System.out.println("enter the 2nd string ");
- String s2 = t.next();
- int n2 = s2.length();
- int i,count=0;
- String temp;
- for(i=0;i<=n1-n2;i++)
- {
- temp = s1.substring(i,i+n2);
- if(s2.equals(temp))
- {
- count++;
- }
- }
- System.out.println("Occurences of 2nd string in 1st string is "+count+" times");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement