用java写个答题系统
时间: 2023-07-30 22:05:45 浏览: 99
用java写的简单的网上答疑管理系统
5星 · 资源好评率100%
好的,下面是一个简单的Java答题系统的代码示例:
```java
import java.util.Scanner;
public class QuizSystem {
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 planet in our solar system?", "Jupiter"},
{"What is the highest mountain in the world?", "Mount Everest"}
};
int score = 0;
for (String[] question : questions) {
System.out.println(question[0]);
String answer = scanner.nextLine();
if (answer.equalsIgnoreCase(question[1])) {
System.out.println("Correct!");
score++;
} else {
System.out.println("Incorrect. The correct answer is " + question[1]);
}
}
System.out.println("Your final score is " + score + "/" + questions.length);
}
}
```
这个答题系统包含了三个问题和对应的答案。程序会依次显示每个问题,等待用户输入答案。如果用户输入的答案与正确答案匹配,则程序会输出"Correct!"并将得分加1;否则输出"Incorrect. The correct answer is xxx"。
最后,程序会计算用户的总分并输出。
阅读全文