用Java写一个在线考试系统的代码
```
//Java Online Exam System
import java.util.*;
public class OnlineExam {
public static void main(String[] args) {
中文写代码软件 //Define array for questions and answers
String[] questions = {"What is the capital of France?",
"What is the capital of Spain?",
"What is the capital of Germany?"};
String[] answers = {"Paris", "Madrid", "Berlin"};
//Welcome message
System.out.println("Welcome to the Online Exam System!");
//Start the exam
Scanner scanner = new Scanner(System.in);
System.out.println("Let's start the exam");
//Loop through each question
int numCorrect = 0;
for (int i = 0; i < questions.length; i++) {
System.out.println(questions[i]);
String answer = Line();
if (answer.equals(answers[i])) {
numCorrect++;
}
}
//Print results
System.out.println("You got " + numCorrect + " out of " + questions.length + " correct!");
}
}
```
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论