简体   繁体   English

在具有 void 返回类型的函数中返回字符串数组

[英]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};
}

} }

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.这意味着您只需要更改函数sports 的返回类型并返回一个有效对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM