public class StringDemo2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入字符串:");
String Max = sc.nextLine();
System.out.println("请输入需要查找的字符串:");
String Min =sc.nextLine() ;
int count = getCount(Max, Min);
System.out.println(count);
}
public static int getCount(String max, String min) {
// TODO Auto-generated method stub
int count = 0;
int index = max.indexOf(min);
while ((index=max.indexOf(min)) != -1) {
count++;
max = max.substring(index + min.length());
//index = max.indexOf(min);
}
return count;
}
}
|
|