0
我正在努力處理這個非常簡單的代碼:我試圖打印出「_」標記,用戶輸入的單詞中的每個字母都帶有一個_標記。然而,每當我嘗試編譯代碼時,我都會得到「錯誤:類game_3中的方法makeLine不能應用於給定類型;原因:實際和正式參數列表的長度不同。」Hang子手遊戲:實際和正式的參數列表長度不一
這似乎很清楚的反饋,但我不認爲我真的明白它 - 起初,我認爲這是因爲我沒有給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("_ ");
}
}
}