Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/357.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何让一个被发现为真的方法在下面显示另一个方法?JAVA_Java_Java.util.scanner_Random - Fatal编程技术网

如何让一个被发现为真的方法在下面显示另一个方法?JAVA

如何让一个被发现为真的方法在下面显示另一个方法?JAVA,java,java.util.scanner,random,Java,Java.util.scanner,Random,我是个新手,除了一部分代码外,我把所有的代码都弄懂了。 假电台 我需要显示一个方法,该方法在一个被发现为true的方法下面包含一条消息 if (seek.equals("down")) { for (int i = 0; i <= 10; i++) { int rmdTest = rmd.nextInt(10); found = rmdTest > 6; if (found

我是个新手,除了一部分代码外,我把所有的代码都弄懂了。 假电台 我需要显示一个方法,该方法在一个被发现为true的方法下面包含一条消息

        if (seek.equals("down")) {
        for (int i = 0; i <= 10; i++) {
            int rmdTest = rmd.nextInt(10);
            found = rmdTest > 6;
                if (found) {
                if (rmdTest == 7)
                    foundStation(98.9, found);
                if (rmdTest == 8)
                    foundStation(100.3, found);
                if (rmdTest == 9)
                    foundStation(107.9, found);

           //This prints out that station is found, but it needs 
           //message that displays the callsign/what's playing
if(seek.equals(“down”)){
对于(int i=0;i 6;
如果(找到){
如果(rmdTest==7)
foundStation(98.9,found);
如果(rmdTest==8)
foundStation(100.3,found);
如果(rmdTest==9)
foundStation(107.9,已找到);
//这会打印出找到车站的信息,但需要
//显示呼号/播放内容的消息

我不完全理解这个问题,但我认为您会从一种更面向对象的方法中获益,例如:

Radio radio = new Radio();
Station station = radio.getCurrentStation();
Callsign callsign = station.getCallsign();
这样,问题的“发现正确”部分由
getCurrentStation
处理,“网络下的消息”部分在
getCallsign
或显示器需要的任何格式的消息中,可能是更新的方法,例如
display.show(callsign)
,或者最好是事件驱动的