// This is the number of occurrences of a statistical string written in Java.Code
/*
* Count the number of times a string appears
*/
Public class twotest {
Public static void main (string [] ARGs ){
String S = "lsdd ";
String y = "iloveyouwhyyoulovemelove ";
System. Out. println (New twotest (). countnumber (S, y ));
}
Public int countnumber (string S, string y) {// Statistical Method
Int COUNT = 0;
String [] K = Y. Split (s); // disconnect the string through S and return array K
If (Y. lastindexof (S) = (Y. length ()-S. length () // if the last index of Y containing S is equal to the length of Y, the number of occurrences is equal to the length of K.
Count = K. length;
Else
Count = K. Length-1; // otherwise, K length-1, because s is not a single character and multiple
If (COUNT = 0)
System. Out. println ("string \" "+ S +" \ "in string \" "+ Y +" \ "no ");
Else
Return count;
Return-1;
}
}