在bluej

时间:2016-09-30 08:55:31

标签: java compiler-errors bluej

我对上述问题持续存在错误。请帮忙..... 我必须在下周五之前将此代码作为我项目的一部分提交。我在互联网上看过其他程序,但他们都使用缓冲读卡器,所以我无法理解。

import java.util.*;
//HANGMAN
//ANSH DAWDA XA
class hangman
{
Scanner S=new Scanner(System.in);
String A,W,word,clue;
void h1()
{
    System.out.println("_____________");
    System.out.println(" |          |");
    System.out.println(" |");
    System.out.println(" |");
    System.out.println(" |");
    System.out.println(" |");
    System.out.println(" |");
    System.out.println(" |");
    System.out.println("---");
}

void h2()
{
    System.out.println("_____________");
    System.out.println(" |          |");
    System.out.println(" |         ( )");
    System.out.println(" |");
    System.out.println(" |");
    System.out.println(" |");
    System.out.println(" |");
    System.out.println(" |");
    System.out.println("---");
}

void h3()
{
    System.out.println("_____________");
    System.out.println(" |          |");
    System.out.println(" |         ( )");
    System.out.println(" |          |");
    System.out.println(" |          |");
    System.out.println(" |          |");
    System.out.println(" |");
    System.out.println(" |");
    System.out.println("---");
}

void h4()
{
    System.out.println("_____________");
    System.out.println(" |          |");
    System.out.println(" |         ( )");
    System.out.println(" |          |");
    System.out.println(" |          |");
    System.out.println(" |          |");
    System.out.println(" |         /");
    System.out.println(" |         |");
    System.out.println("---");
}

void h5()
{
    System.out.println("_____________");
    System.out.println(" |          |");
    System.out.println(" |         ( )");
    System.out.println(" |          |");
    System.out.println(" |          |");
    System.out.println(" |          |");
    System.out.println(" |         / \\");
    System.out.println(" |         | |");
    System.out.println("---");
}

void h6()
{
    System.out.println("_____________");
    System.out.println(" |          |");
    System.out.println(" |         ( )");
    System.out.println(" |          |");
    System.out.println(" |         /|");
    System.out.println(" |        / |");
    System.out.println(" |         / \\");
    System.out.println(" |         | |");
    System.out.println("---");
}

void h7()
{
    System.out.println("_____________");
    System.out.println(" |          |");
    System.out.println(" |         ( )");
    System.out.println(" |          |");
    System.out.println(" |         /|\\");
    System.out.println(" |        / | \\");
    System.out.println(" |         / \\");
    System.out.println(" |         | |");
    System.out.println("---");
}
int option;
void sports()
{
    option=(int)(Math.random()*10);
    switch(option)
    {   case 0:
        {
            clue = "He is an Argentine footballer who plays for La Liga club FC Barcelona and is the captain of the Argentina national team, playing mainly as a forward.";
            word = "LIONEL MESSI";
        }
        break;
        case 1:
        {
            clue = "First person to score 200 in ODIs";
            word = "SACHIN TENDULKAR";
            break;
        }
        case 2:
        {
            clue = "It is a South Asian team sport.";
            word = "KABADDI";
        }
        break;
        case 3:
        {
            clue = "It is a twoplayer board game";
            word = "CHESS";
        }
        break;
        case 4:
        {
            clue = "It is a team sport in which two teams of six players are separated by a net.";
            word = "VOLLEYBALL";
        }
        break;
        case 5:
        {
            clue = "Known as 'The wall'";
            word = "RAHUL DRAVID";
        }
        break;
        case 6:
        {
            clue = "World Table Tennis Champion";
            word = "ZHANG JIKE";
        }
        break;
        case 7:
        {
            clue = "A famous sport";
            word = "FOOTBALL";
        }
        break;
        case 8:
        {
            clue = "Played on a hard board divided by a net";
            word = "TABLE TENNIS";
        }
        break;
        case 9:
        {
            clue = "Grandmaster of chess";
            word = "VISHWANATAN ANAND";
        }
        break;
    }
    return String {word,clue};
}

}

1 个答案:

答案 0 :(得分:0)

请更改您的功能

void sports() {

    // Code 

        return String {word,clue};
    }

要:

String[] sports() {

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

它意味着您只需要更改函数sports的返回类型并返回有效对象。