public class TestDemo3 {
public static void main (String[] args){
String str = "avecefewfew";
// System.out.println(myIndexOf(str,'e',3));
// System.out.println(myContains(str,"abc"));
// System.out.println(myComepareTo(str,"avecefewfew"));
// System.out.println(myComepareTo(str,"sahdsh"));
System.out.println(myComepareTo(str,"abeceedwder"));
System.out.println((int)str.charAt(0));
}
//自己的indexo方法
public static int myIndexOf(String str,char x,int t){
for (int i = t; i < str.length(); i++) {
char n = str.charAt(i);
if(n == x){
return i;
}
}
return -1;
}
public static boolean myContains(String str ,String s){
int n = s.length();
for (int i = 0; i < str.length() - n ; i++) {
if(str.substring(i,i + n).equ
Java中实现自己的indexOf方法,contains方法以及comepareTo方法
最新推荐文章于 2022-03-31 08:54:00 发布