/*** Created by Administrator on 2016/9/18.*/ Public classEmployee { PublicString name; Public intAge ; //return personal Information PublicString toString () {return"My name is" +name+ ", this year:" +Age ; } //The number of occurrences of the corresponding string found in the specified string/** src friend ah friend, you are my best friend * DST friend * indexOf ("friend") **/ Public intcountcontent (String src,string DST) {intcount=0;//counter intindex=0;//Save the subscript to find a friendindex=Src.indexof (DST); //Indeindeof found the first occurrence of the subscript, can not find the return-1 while(Index!=-1) {Count++; Index+=dst.length ();//specify from which subscript to look backindex=Src.indexof (Dst,index); } returncount; } Public Static voidmain (String [] args) {Employee emp=NewEmployee (); Emp.name= "Zhang San"; Emp.age=30; System.out.print (Emp.tostring ()); String src= "friend, friend, you are my best friend."; String DST= "Friends"; intCount=emp.countcontent (SRC,DST); System.out.print (DST+ "The number of occurrences is" +count+ "Times"); }}
Java, write an employee class