- public class tqc210
- {
- public static void main(String args[])
- {
- Scanner s=new Scanner(System.in);
- System.out.println("請輸入字串");
- String str=s.nextLine();
- System.out.println("請輸入要搜尋的字元");
- String str1=s.nextLine();
- int lofc=-1;
- boolean find=false,find1=false;
- do
- {
- loc=str.indexOf(str1,loc+1);
- if(loc>-1)
- {
- if(!find)
- {
- System.out.println("第幾個位置找到了");
- find1=true;
- }
- find1=true;
- System.out.println(loc+1);
- }
- }while(loc!=-1)
- if(!find1)
- System.out.println("搜尋的字元不在字元中");
- }
- }
複製代碼 |