import?java.io.*;
public?class?Test
{
public?static?void?main(String[]?args)?throws?Exception
{
String?str?=?"abcaaabckljldabcljljf";
BufferedReader?br?=?new?BufferedReader(new?InputStreamReader(System.in));
System.out.println("請輸入要查找的單詞");
String?findStr?=?br.readLine();
int?strIndex?=?0;
int?sum?=?0;
if?(findStr?!=?null?&&?findStr.length()?!=?0)
{
strIndex?=?str.indexOf(findStr);
if?(strIndex?==?-1)
{
System.out.println("沒找到");
}
else
{
System.out.print("位置:");
while?(strIndex?!=?-1)
{
System.out.print(strIndex?+?"?");
//從之前找的位置的後面接著找
strIndex?=?str.indexOf(findStr,?strIndex?+?1);
sum++;
}
System.out.println("\r\n總***:"?+?sum?+?"個");
}
}
}
}