Programming 1 Unit 1
Programming 1 Unit 1
import java.util.Scanner;
int score = 0;
// Question 1
System.out.println("A) Madrid");
System.out.println("B) Berlin");
System.out.println("D) Rome");
System.out.println("Correct!");
score++;
} else {
// Question 2
System.out.println("Question 2: Which of the following is not an animal?");
System.out.println("A) Dog");
System.out.println("B) Cat");
System.out.println("C) goat");
System.out.println("D) hen");
answer = scanner.next();
if (answer.equalsIgnoreCase("D) hen")) {
System.out.println("Correct!");
score++;
} else {
// Question 3
answer = scanner.next();
System.out.println("Correct!");
score++;
} else {
// Question 4
System.out.println("A) Mercury");
System.out.println("B) Venus");
System.out.println("C) Earth");
System.out.println("D) Mars");
answer = scanner.next();
if (answer.equalsIgnoreCase("C) Earth")) {
System.out.println("Correct!");
score++;
} else {
// Question 5
System.out.println("A) plastics");
System.out.println("D) Vegetables");
answer = scanner.next();
if (answer.equalsIgnoreCase("D) Vegetables")) {
System.out.println("Correct!");
score++;
} else {
This program prompts the user with five multiple-choice questions and allows them to enter their
answers. After the user has entered their answer for each question, the program compares it to the
correct answer and keeps track of the score. Finally, the program displays the final score based on the
number of correct answers.