Hi!
Kleiner Tippfehler: System.out.println("String_1
: + "string);
Folgendermaßen funktioniert es:
Code:
public static int INDEX(String string, String element) {
int temp = -1;
if (string == null || element == null)
return -1;
else {
temp = string.indexOf(element);
System.out.println("String_1: " + string);
System.out.println("Element: " + element);
}
return temp;
}
public static void main (String[] args) {
System.out.println("temp: " + INDEX("String_1, String_2", "String_1"));
}
Ergibt:
Zitat:
String_1: String_1, String_2
Element: String_1
temp: 0