请教java中indexOf()的问题

来源:百度知道 编辑:UC知道 时间:2024/05/30 10:21:42
public class String_Example {
public static void testFindStr(String str){
System.out.println("str.indexOf(\"is\") = " + str.indexOf("is"));
}

public static void main(String args[]){

String str = "This is a String object!";
System.out.println("str的值:" +str);
}
}
为何此程序不返回indexOf()的结果呢
public class String_Example {

//public static int getIndex (String str1 ){
//System.out.println("Go");
//return str1.indexOf("aab");
public static int testFindStr(String str,String str2){
return str.indexOf(str2);
//System.out.println("str.indexOf(\"is\") = " + str.indexOf("is"));
}

// }
public static void main(String args[]){
// String str1 = "aabbccddabcdaaa";
//Str

public class String_Example {
public static void testFindStr(String str){
System.out.println("str.indexOf(\"is\") = " + str.indexOf("is"));
}

public static void main(String args[]){

String str = "This is a String object!";
System.out.println("str的值:" +str);
}
}
===以上这段程序并没有调用你写的testFindStr方法,所以不会打印出indexOf的结果。

public static void main(String args[]){
// String str1 = "aabbccddabcdaaa";
//String str2 = "abc";
// String_Example.getIndex(str1 );
String str = "This is a String object!";
String str2 = "String";
System.out.println("str的值:" +str);
String_Example.testFindStr(str,str2);
}
==以上这段程序并没有要打印indexOf的语句,结果肯定是返回了,因为在这里你调用了写的indexOf方法。

public static void main(String args[]){
// String str1 = "aabbccddabcdaaa";
//Str