0

次のコードでは、テキスト ファイルの一部を比較しようとしています。ただし、何らかの理由で、ユーザーが値に何を入力しても正しく表示されます。

大文字と小文字、または先頭または末尾の空白を気にせずに値を比較しようとしています。

// Display the question to the user
System.out.println("Question: " + myList.get(random1));

// Accept user input
System.out.print("Please type your answer: ");

// Store the user answer in a variable but lowercase
answer = scanner.nextLine().toLowerCase();
System.out.println();

// Display the officially correct answer from the arraylist
System.out.println("Answer: " + myList.get(random1 +1));

// if the user answer matches the official answer, tell them they're
// correct and award points
// else tell them they suck LOL
if(myList.get(random1 + 1).contains(answer) == false) {
    System.out.println("Correct!");
    totalScore = totalScore + awardedPoints;
    System.out.println("You won " + awardedPoints);
}
else {
    System.out.println("You suckkkkkkk");
}

// Display total accumulated points
System.out.println("Your total points are: " + totalScore);

// Wait for user to hit any key before displaying the next question
System.out.print("Hit Enter");
scanner.nextLine();
4

1 に答える 1