I am making a trivia game, in this one section I am trying to check if the variable 'a' is equal to any of the elements in the array. In this particular context, I'm trying to see if it is equal to 3 OR 1964. NOTE: I shortened the code to get rid of any extra code, and the '//...' represents that I skipped several lines of code.
class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
//...
int[] answer1 = {3, 1964}
//...
do {
System.out.println("Enter your answer now.");
int a = input.nextInt();
if (a != answer1[]) {
System.out.println("Incorrect. Try again.");
guess_count++;
} else {
System.out.println("Correct! You gained 1 point!");
pointTotal++;
guessCount++;
}
Aucun commentaire:
Enregistrer un commentaire