返回列表 發帖
  1. public class ch70
  2. {
  3.   public static void main(String args[])
  4.   {
  5.     Stirng str1="An apple a day keeps the doctor away!";
  6.     String str2="apple";
  7.     String str3="banana";
  8.     System.out.println("字串"+str1);
  9.     System.out.println("第一個p出現在字串裡的第"str1.indoxOf("p")+"個位置");
  10.     System.out.println("自第8個位置往後找,第一個a出現在字串裡的第"+str1.indexOf("a"+8)+"個位置");
  11.     System.out.println("自第8個位置往後找,最後一個a出現在字串裡的第"+str1.lastIndexOf("a"+8)+"個位置");
  12.     if(str1.indoxOf(str2)<0)
  13.     System.out.println("字串裡找不到"+str2);
  14.     else
  15.     System.out.println("字串裡有"+str2+"出現在第"+str1.indexOf(str2)+"個位子");
  16.     if(str1.indexOf(str3)<0)
  17.     System.out.println("字串裡找不到"+str3);
  18.     else
  19.     System.out.println("字串裡有"+str3+"出現在第"+str1.indexOf(str3)+"個位子");
  20.   }
  21. }
複製代碼

TOP

返回列表