用Java编写个浏览器,输入字符串以及需要查到的字符

2024-10-31 06:13:48
推荐回答(1个)
回答1:

Scanner input = new Scanner(System.in);
System.out.print("请输入一段字符:");
String s = input.next();
System.out.println("请输入要查询的字符串:");
String a = input.next();

int index = s.indexOf(a);
List ls = new ArrayList();
while (index >= 0)
{
ls.add(index);
index = s.indexOf(a, index + 1);
}
for(Object i : ls)
{
System.out.print(i + " ");
}