String word="i love apples i love orange";
String w=scan.next();
int index = word.indexOf(w);
System.out.println (index);
while (index >= 0) {
System.out.println(index);
index = word.indexOf(w, index + 1);
}
所以我知道这段代码会告诉我爱的索引是(2,17),但我要找的是我希望它为我返回单词的索引是(1,4),也就是说它很重要字符串中的字符串而不是字符......我也需要它来指示索引,每次它找到它就像上面的那个一样谢谢