我写了下面几句代码,想试试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 错误
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 错误
public static void main(String[] args){
String greeting="abcdefg";
String cp="cd";
int i=greeting.lastindexOf(cp);
System.out.println(i);
}
}
public static void main(String[] args){
String greeting="abcdefg";
int cp=4;
int i=greeting.lastindexOf(cp);
System.out.println(i);
}
} 红色部分拼写错误,应为:lastIndexOf
int lastIndexOf(int ch)
返回最后一次出现的指定字符在此字符串中的索引。
int lastIndexOf(int ch, int fromIndex)
从指定的索引处开始进行后向搜索,返回最后一次出现的指定字符在此字符串中的索引。
int lastIndexOf(String str)
返回在此字符串中最右边出现的指定子字符串的索引。
int lastIndexOf(String str, int fromIndex)
从指定的索引处开始向后搜索,返回在此字符串中最后一次出现的指定子字符串的索引。
lastIndexOf(string s)也可以是String
返回最后一次出现的指定字符在此字符串中的索引。
int lastIndexOf(int ch, int fromIndex)
从指定的索引处开始进行后向搜索,返回最后一次出现的指定字符在此字符串中的索引。
int lastIndexOf(String str)
返回在此字符串中最右边出现的指定子字符串的索引。
int lastIndexOf(String str, int fromIndex)
从指定的索引处开始向后搜索,返回在此字符串中最后一次出现的指定子字符串的索引。
第一个。。
可是lastindex()的参数也可以是int"int lastindexOf(int ch)
返回最后一次出现的指定字符在此字符串中的索引。"
可是lastindex()的参数也可以是int "int lastindexOf(int ch)
返回最后一次出现的指定字符在此字符串中的索引。"
返回最后一次出现的指定字符在此字符串中的索引。小写