A simple console-based Quiz Game built in Java using loops, arrays, and the Scanner class.
This game asks multiple-choice questions, checks your answers, and updates your score in real-time!
| Concept / Method | Purpose |
|---|---|
Scanner |
Read input from the user |
for loop |
Iterate through the questions |
String[] array |
Store quiz questions |
String[][] 2D array |
Store multiple options per question |
char[] array |
Store correct answers (A/B/C/D) |
charAt(0) method |
Get the first character from user input |
toUpperCase() method |
Standardize user input for comparison |
System.out.println() |
Display output on console |
if-else statement |
Compare user input with correct answer and update score |
main Methodpublic static void main(String[] args)
- Entry point of the program
String[] questions;
String[][] options;
char[] answers;
questions[]: Stores all quiz questionsoptions[][]: Stores 4 options per questionanswers[]: Stores correct answers in char formatfor (int i = 0; i < questions.length; i++)
Scanner scanner = new Scanner(System.in);
char userAnswer = Character.toUpperCase(scanner.next().charAt(0));
if (userAnswer == answers[i]) {
// Correct!
} else {
// Incorrect
}
Question 1: What is the output of 5 + 3? A. 53 B. 8 C. Error D. None Your answer (A/B/C/D): B ✅ Correct! Current Score: 1/1 ... 🎉 Quiz Over! Your Final Score: 5/5
MiniQuizGame.javajavac MiniQuizGame.java
java MiniQuizGame
Collections.shuffle().txt or .csv fileSanskriti Singh
This project is open for educational purposes. Feel free to fork and improve!