// 输入一串字符,查询某个字符出现的位置
import java.util.Scanner;
public class Search_Site {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.print("请输入一段字符:");
String words = input.next();
System.out.print("请输入要查询的字符串:");
String search = input.next();
String[] in = new String[words.length()];
for(int i=0; i<in.length; i++ ){
in[i] = words.substring(i,i+1);
}
System.out.println(search + "出现的位置是:");
for(int i=0; i<in.length; i++){
if (in[i].equals(search)){
System.out.print((i+1)+ " ");
}
}
}
}
输入一串字符,查询某个字符出现的位置
最新推荐文章于 2022-12-01 16:30:34 发布