im trying to get the index of a character using only the charAt and length methods for strings. this is what the question asks :Declare a public method called indexOf that takes a character parameter and returns the index in the stored string of the first occurrence of that character or -1 if the character is not found. this is what i did.
public int indexOf(char c){
for(i=0; i <string.length - 1; i++){
if(string.charAt(c) == string.charAt(i)){
return i;
else {
return -1;
}
}