我正在努力处理这个非常简单的代码:我正在尝试打印出“_”标记,用户输入的单词中的每个字母都有一个 _ 标记。但是,每当我尝试编译代码时,我都会收到“错误:game_3 类中的方法 makeLine 不能应用于给定类型;原因:实际参数列表和形式参数列表的长度不同。”
这似乎是非常明确的反馈,但我认为我并没有真正理解它 - 起初,我认为这是因为我没有为 stringNumber 分配值,但为其分配值并没有帮助。怎么了?
/*Assignment:
Write a reverse Hangman game in which the user thinks of a word and the computer tries
to guess the letters in that word. Your program must output what the computer guessed
on each turn, and show the partially completed word. It also must use pseudorandom
functions to make guesses. That is, it should not simply try all the letters in order,
nor should it use the user’s input to its advantage.
*/
import java.util.*;
public class game_3 {
public static void main(String[] args) {
getIntroduction();
playGame();
}
public static void getIntroduction(){
System.out.println();
System.out.println();
System.out.println("*************************");
System.out.println("Welcome to Hangman");
System.out.println("In this game, you'll provide a word for the computer to guess.");
System.out.println();
System.out.println("The computer will guess letters randomly, and assess whether");
System.out.println("they can be used to complete your word.");
System.out.println();
System.out.println("Let's play!");
System.out.println();
System.out.println("*************************");
System.out.println();
}
public static void playGame(){
Scanner input = new Scanner(System.in);
System.out.print("Please enter a word: ");
String hangWord = input.next();
int stringNum = hangWord.length();
makeLine();
}
public static void makeLine(int stringNum){
for (int i = 0; i < stringNum; i++){
System.out.print("_ ");
}
}
}