importjava.io.*;
importjava.util.regex.*;
classJString{
publicstaticvoidmain(String[]args){//主函数
BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));
try{
intn=0;
Stringstr="";
System.out.println("请输入大于1的数字");
Patternpt1=Pattern.compile("[0-9]*$");//正则表达式匹配数字
Stringline1=br.readLine();
Matcherm=pt1.matcher(line1);
if(m.matches()){
n=Integer.parseInt(line1);
if(n1){
System.out.println("请输入仅包含小写的字符串");//正则表达式匹配字符串
pt1=Pattern.compile("[a-z]*$");
str=br.readLine();
m=pt1.matcher(str);
if(m.matches()){
if((str.length()=n)(str.length()=10000)){
intlen=str.length();
intcount=0,tmpcnt=0;
Stringtmpstr="";
for(inti=0;ilen-n;i++){
tmpcnt=0;
tmpstr=str.substring(i,i+n);
intj=i;
while(j=len-n){
if((str.substring(j,j+n)).equals(tmpstr)){
tmpcnt++;
j+=n;
}else{
j++;
}
if(tmpcntcount){
count=tmpcnt;//若当前n值大于以保存的最大值,记录当前值
}
}
}
System.out.println("输出结果为:"+count);
}
}
}
}
}catch(Exceptionex){
System.out.println("error:"+ex.getMessage());
}
}
}
已投稿到:阅读||||前一篇:
评论[发评论]发评论
验证码:
发评论
0 评论:
发表评论