/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication26;
import java.util.Scanner;
/**
*
* @author 86188
*/
class question2{
public static void main(String[] args) {
Scanner in =new Scanner(System.in);
System.out.println("请输入字符串1");
String str1=in.next();
System.out.println("请输入字符串2");
String str2=in.next();
int result=str1.indexOf(str2);
int[] loc=new int[10];
int i=0;
while(result!=-1)
{
loc[i]=result;
str1=str1.replaceFirst(str2, "##");
result=str1.indexOf(str2);
i=i+1;
}
if(i==0)
{System.out.println("str1中不存在str2");}
else
{
System.out.print("str1中存在str2,且位置在:");
for(int j=0;j<i;j++)
{
System.out.print(loc[j]+",");
}
}
}
}
01-21
3084
12-17
1074