public class Employeedemo {//Method one: public int search (string str,string strres) {//lookup string in the same number as the specified string int n=0;//counter//for (int i = 0;i<str.length (); i++) {////}while (Str.indexof (strres)!=-1) {int i = Str.indexof (strres); n++;str = Str.substring ( i+1);} return n;} Method two: public int search2 (String str,string strres) {int n = 0;//counter int index = 0;//Specifies the length of the character index = Str.indexof (strres); whil E (index!=-1) {n++;index = Str.indexof (strres,index+1);} return n;} public static void Main (string []args) {string arr = "friend, friend, how are you now?" "; Employeedemo emp = new Employeedemo (); System.out.println (Emp.search (arr, "Friends")); System.out.println (EMP.SEARCH2 (arr, "Friend"));}}
The same number in the Java lookup string as the specified string