2016-09-30 37 views
-2

我对上述问题持续发生错误。请帮助..... 我必须在下周五之前将此代码作为我项目的一部分提交。我在网上看过其他程序,但都使用缓冲区读取器,所以我不能理解。在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

@Simze为什么?这很好。问题是最后一个方法最后的return语句。 – f1sh

+0

@Ansh你的方法''体育''有返回类型的void,这意味着你不能返回任何东西。然而,这就是你在这里尝试的:''返回String {word,clue};''。这个陈述也不是一个有效的表达。 – f1sh

+0

对不起我的坏!已删除评论 –

回答

0

请更改功能

void sports() { 

    // Code 

     return String {word,clue}; 
    } 

要:

String[] sports() { 

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

这意味着你只需要改变的功能运动的返回类型,并返回一个有效的对象。