我有一个游戏程序,其中要求用户猜测给定的加扰字.
例如:乱码:loglab你的猜测:
这个词是全球性的,每次我输入"GLOBAL"时它都说这个词是不正确的.我试图使用toUpperCase但它没有用.我的程序如何能够接受输入的字符串,即使它是大写的?以下是我的一些代码.我不会发布它,因为它太长了,但如果你需要更多它只是通知我.关于此事,请帮助我,谢谢.
StaticWordLibrary.java:
public boolean isCorrect(int idx, String userGuess) { return userGuess.equals(getWord(idx)); }
WordLibrary.java:
public abstract boolean isCorrect(int idx, String userGuess);
Anagrams.java:
private void guessedWordActionPerformed(java.awt.event.ActionEvent evt) { if (wordLibrary.isCorrect(wordIdx, guessedWord.getText())){ JOptionPane.showMessageDialog(null, "Your answer is correct! Guess another word.","", JOptionPane.INFORMATION_MESSAGE); getRootPane().setDefaultButton(nextTrial); } else { JOptionPane.showMessageDialog(null, "Your answer is incorrect! Please try again.","", JOptionPane.ERROR_MESSAGE); guessedWord.setText(""); } guessedWord.requestFocusInWindow(); }
小智.. 5
使用equalsIgnoreCase()
而不仅仅是equals()
使用equalsIgnoreCase()
而不仅仅是equals()