0
我試着去得到一個userValue返回如果userValue不等於某個詞。所以基本上必須匹配我的話(有是微積分),如果它不那麼它返回到提示用戶再次嘗試。林不知道是否有一個特定的代碼或不。的Java:如何設置我的代碼,這樣,如果一個userValue不等於某個詞然後將返回
抱歉,我有我上傳的代碼的麻煩,如果有人知道如何,請您幫助我。
我試着去得到一個userValue返回如果userValue不等於某個詞。所以基本上必須匹配我的話(有是微積分),如果它不那麼它返回到提示用戶再次嘗試。林不知道是否有一個特定的代碼或不。的Java:如何設置我的代碼,這樣,如果一個userValue不等於某個詞然後將返回
抱歉,我有我上傳的代碼的麻煩,如果有人知道如何,請您幫助我。
的答案几乎肯定要使用一個循環,最簡單的方法很可能是這樣的 -
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String toFind = "calculus";
String word = null;
// or just ".equals" if it should be case sensitive.
while (!toFind.equalsIgnoreCase(word)) {
if (word != null) {
System.out.print("Incorrect. ");
}
System.out.print("Please guess a word: ");
System.out.flush();
if (!scanner.hasNextLine()) {
break;
}
word = scanner.nextLine();
}
System.out.println("Correct, the word was " + toFind);
}
幫助中心可以_help_你。 –
我可以在哪裏訪問? – user3357247
旁邊的搜索欄在頁面的右上角。 –