返回列表 發帖
  1. public class ch56
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         String str="An apple a day keeps the doctor away!";
  6.         System.out.println("字串: "+str);
  7.         System.out.println("第一個a出現在字串裡的第"+str.indexOf("a")+"個位置");
  8.         System.out.println("最後一個a出現在字串裡的第"+str.lastIndexOf("a")+"個位置");
  9.         System.out.println("針對第8個位置之後的部分搜尋, 第一個a出現在字串裡的第"+str.indexOf("a",8)+"個位置");
  10.         System.out.println("針對第8個位置之前的部分搜尋, 最後一個a出現在字串裡的第"+str.lastIndexOf("a",8)+"個位置");
  11.     }
  12. }
複製代碼

TOP

返回列表