Created
April 26, 2023 08:06
-
-
Save R3DHULK/f94786ba7c0b5757e606cc96423b8c48 to your computer and use it in GitHub Desktop.
Trivia Game Written In Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class trivia { | |
public static void main(String[] args) { | |
Scanner scanner = new Scanner(System.in); | |
String[][] questions = { | |
{"What is the capital of France?", "Paris"}, | |
{"What is the largest country in the world?", "Russia"}, | |
{"What is the smallest country in the world?", "Vatican City"} | |
}; | |
int score = 0; | |
for (int i = 0; i < questions.length; i++) { | |
System.out.println(questions[i][0]); | |
String answer = scanner.nextLine().trim(); | |
if (answer.equalsIgnoreCase(questions[i][1])) { | |
System.out.println("Correct!"); | |
score++; | |
} else { | |
System.out.println("Incorrect. The correct answer is: " + questions[i][1]); | |
} | |
} | |
System.out.println("Your final score is: " + score); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment