java如何在另一个字符串中搜索字符串
我正在尝试创建一个程序,它将能够搜索用户输入的字符串中的特定单词,并计算该单词的重复次数
例如,我希望程序的功能如下:
Please enter a string of your choice:
kelowna is a nice city, kelowna is my home.
Enter a word for which you would like to search for:
kelowna
The word Kelowna was found 2 times.
我该怎么做呢?我最初的方法是使用循环,但这并没有让我走得太远
这就是我目前的情况:
import java.util.Scanner;
public class FinalPracc {
public static void main(String[] args) {
Scanner s1 = new Scanner(System.in);
System.out.println("please enter a string of you choice: ");
String a = s1.nextLine();
System.out.println("Please enter the word you would like to search for: ");
String b = s1.nextLine();
int aa = a.length();
int bb = b.length();
if (a.contains(b)) {
System.out.println("word found");
int c = a.indexOf(b);
int
if (
}
}
/* ADD YOUR CODE HERE */
}
共 (0) 个答案