返回列表 發帖
  1. public class tqc210
  2. {
  3.   public static void main(String args[])
  4.   {
  5.     Scanner s=new Scanner(System.in);
  6.     System.out.println("請輸入字串");
  7.     String str=s.nextLine();
  8.     System.out.println("請輸入要搜尋的字元");
  9.     String str1=s.nextLine();
  10.     int lofc=-1;
  11.     boolean find=false,find1=false;
  12.     do
  13.     {
  14.       loc=str.indexOf(str1,loc+1);
  15.       if(loc>-1)
  16.       {
  17.         if(!find)
  18.         {
  19.           System.out.println("第幾個位置找到了");
  20.           find1=true;
  21.         }
  22.         find1=true;
  23.         System.out.println(loc+1);
  24.       }
  25.     }while(loc!=-1)
  26.       if(!find1)
  27.         System.out.println("搜尋的字元不在字元中");



  28.   }
  29. }
複製代碼

TOP

返回列表