我需要检查用户输入的字母以及他们猜测的空格是否位于隐藏字的特定位置.
变量1等于用户猜测的空间索引..而letterGuess是他们猜测的字母.我的代码怎么样错了?
例如:秘密字是你好
hidden word is == -----
Run Code Online (Sandbox Code Playgroud)
用户猜测h 0 1 2 3
,它需要检查单词索引0 1 2 3处的空格是否hello包含用户猜测"h",如果是,则需要替换-----为h----.
String firstSpace = guessedSpaces.substring(0,1);
String secondSpace = guessedSpaces.substring(2,3);
String thirdSpace = guessedSpaces.substring(4,5);
String fourthSpace = guessedSpaces.substring(6,7);
int one = Integer.parseInt(firstSpace);
int two = Integer.parseInt(secondSpace);
int three = Integer.parseInt(thirdSpace);
int four = Integer.parseInt(fourthSpace);
(secretWord.charAt(one)==letterGuess)
(secretWord.charAt(one)==letterGuess)
(secretWord.charAt(one)==letterGuess)
(secretWord.charAt(one)==letterGuess)
Run Code Online (Sandbox Code Playgroud) java ×1