Search code examples
javacompiler-errorsbluej

Returning String array in a function with void return type


I am getting continuous errors about the above matter. Please help..... I have to submit this code as a part of my project by next Friday. I have seen other programs on the internet but they all use buffer reader so I cant understand.

void sports()
{
    
    String word, clue;
    
    <code related to initialization of word and clue>

    return String {word,clue};
}

}


Solution

  • Please Change your function

    void sports() {
    
        // Code 
    
            return String {word,clue};
        }
    

    To:

    String[] sports() {
    
            // Code 
            return new String[]{word, clue};
        }
    

    it Means you just have to change your return type of function sports and return a valid object.