Q:

Returning a char from a method

I don't know what's wrong, but I can't get this method to return the characters I'm wanting it to. I just keep getting an error in the form of red lines under the word 'return'
Here's my method.
public static char getOperator(String fileContent){

    int checkAdd = fileContent.indexOf('+');
    int checkMinus = fileContent.indexOf('-');
    int checkMulti = fileContent.indexOf('*');
    int checkDivi = fileContent.indexOf('/');

    if (checkAdd != -1){
        return char operator = fileContent.charAt(fileContent.indexOf('+')); 
    }   
    else if (checkMinus != -1) {
        return char operator = fileContent.charAt(fileContent.indexOf('-'));
    }
    else if (checkMulti != -1) {
        return char operator = fileContent.charAt(fileContent.indexOf('*'));
    }
    else if (checkDivi != -1){
        return char operator = fileContent.charAt(fileContent.indexOf('/'));
    }
    return 0;

    }

Okay, sorry about that, I had been messing with it in eclipse and didn't catch that issue. However, now the return statements in the ifs still produce errors. How do I fix that?

A:

Try this out
public static char getOperator(String fileContent){

    int checkAdd = fileContent.indexOf('+');
    int checkMinus = fileContent.indexOf('-');
    int checkMulti = fileContent.indexOf('*');
    int checkDivi = fileContent.indexOf('/');

    if (checkAdd != -1){
        char operator = fileContent.charAt(checkAdd); 
        return operator;
    }   
    else if (checkMinus != -1) {
        char operator = fileContent.charAt(checkMinus);
        return operator;
    }
    else if (checkMulti != -1) {
        char operator = fileContent.charAt(checkMulti);
        return operator;
    }
    else if (checkDivi != -1){
        char operator = fileContent.charAt(checkDivi);
        return operator;
    }

    return ' ';
}

