package com.atguigu.java1;
import java.util.Scanner;
public class huoqucishu {
public static void main(String[] args) {
String s1 = "abc abc abc abc abc";
huoqucishu h = new huoqucishu();
System.out.println(h.getNode(s1));
}
public String getNode(String s){
String s1;
System.out.println("请输入要查找的子字符串");
Scanner scan = new Scanner(System.in);
String in = scan.nextLine();
int index = s.indexOf(in);
if(index == -1){
return String.valueOf(-1);
}
s1 = s.substring(index + in.length() - 1);
int total = 0;
while (index != -1) {
s1 = s1.substring(index + in.length());
index = s1.indexOf(in);
total++;
}
return String.valueOf(total);
}
}