public class Chazhao {
public static void main(String []args){
long startTime=System.nanoTime();
String s1="java";
String s2="abcjava testjava javatest ajavab java";
int n=0;
for(int i=0;i<s2.length();i++){
if(s1.regionMatches(0,s2,i,4))
n++;
}
System.out.println("字符串出现的Java数量为:"+n);
long estimatedTime=System.nanoTime()-startTime;
System.out.println("共花了"+estimatedTime+"毫微妙");
long startTime1=System.nanoTime();
int m=0;
char [] str=s2.toCharArray();
for(int i=0;i<s2.length();i++){
if(str[i]=='j'&&str[i+1]=='a'&&str[i+2]=='v'&&str[i+3]=='a')
m++;
}
System.out.println("字符串出现的Java数量为:"+m);
long estimatedTime1=System.nanoTime()-startTime1;
System.out.println("共花了"+estimatedTime1+"毫微妙");
}
}