我写了下面几句代码,想试试lastindexOf()方法,可怎么也调试不通,不知道错哪里了,请大家帮帮忙,谢谢了!
public class LastIndex{
public static void main(String[] args){
String greeting="abcdefg";
int cp=4;
int i=greeting.lastindexOf(cp);
System.out.println(i);
}
}错误提示:
LastIndex.java:5: 找不到符号
符号: 方法 lastindexOf(int)
位置: 类 java.lang.String
                int i=greeting.lastindexOf(cp);
                              ^
1 错误

解决方案 »

  1.   

    lastIndexOf()方法的参数是String类啊。改为如下试试:public class LastIndex{ 
        public static void main(String[] args){ 
            String greeting="abcdefg"; 
            String cp="cd"; 
            int i=greeting.lastindexOf(cp); 
            System.out.println(i); 
        } 

      

  2.   

    public class LastIndex{ 
    public static void main(String[] args){ 
    String greeting="abcdefg"; 
    int cp=4; 
    int i=greeting.lastindexOf(cp); 
    System.out.println(i); 

    } 红色部分拼写错误,应为:lastIndexOf
      

  3.   

    应该是lastIndexOf()吧,Index的I要大写
      

  4.   

    另:
     int lastIndexOf(int ch) 
              返回最后一次出现的指定字符在此字符串中的索引。 
     int lastIndexOf(int ch, int fromIndex) 
              从指定的索引处开始进行后向搜索,返回最后一次出现的指定字符在此字符串中的索引。 
     int lastIndexOf(String str) 
              返回在此字符串中最右边出现的指定子字符串的索引。 
     int lastIndexOf(String str, int fromIndex) 
              从指定的索引处开始向后搜索,返回在此字符串中最后一次出现的指定子字符串的索引。 
      

  5.   

    lastIndexOf(int ch)的参数可以是int,返回最后一次出现的指定字符在此字符串中的索引
    lastIndexOf(string s)也可以是String
      

  6.   

    lastIndexOf(),可能拼写错了,int做参数是可以的
      

  7.   

     int lastIndexOf(int ch) 
              返回最后一次出现的指定字符在此字符串中的索引。 
     int lastIndexOf(int ch, int fromIndex) 
              从指定的索引处开始进行后向搜索,返回最后一次出现的指定字符在此字符串中的索引。 
     int lastIndexOf(String str) 
              返回在此字符串中最右边出现的指定子字符串的索引。 
     int lastIndexOf(String str, int fromIndex) 
              从指定的索引处开始向后搜索,返回在此字符串中最后一次出现的指定子字符串的索引。 
     第一个。。
      

  8.   

    谢谢你,
    可是lastindex()的参数也可以是int"int lastindexOf(int ch) 
    返回最后一次出现的指定字符在此字符串中的索引。"
      

  9.   

    谢谢你, 
    可是lastindex()的参数也可以是int "int lastindexOf(int ch) 
    返回最后一次出现的指定字符在此字符串中的索引。"
      

  10.   

    int lastindexOf(int ch) 
    返回最后一次出现的指定字符在此字符串中的索引。小写