Sunday, 30 November 2014

find the substring count from a string without string functions in java

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;



public class SB

{




public static void main(String[] args) {

{
String test=null;
String index=null;
int j=0;
System.out.println("Enter the string");
test= new Scanner(System.in).nextLine();
System.out.println("Enter the substring you want to count");
index= new Scanner(System.in).nextLine();
for (int i = 0; i <= test.length()-index.length(); i++) {
String testing=test.substring(i, index.length()+i);

if(testing.equals(index))
{
j++;

}
}
System.out.println("No of count is "+j);
}
}
}










No comments:

Post a Comment