Java入门级程序 :Problem: Grading a Multiple-Choice Test
发布日期:2021-06-29 11:49:47 浏览次数:2 分类:技术文章

本文共 1350 字,大约阅读时间需要 4 分钟。

The problem is to write a program that grades multiple-choice tests. Suppose there are eight students and ten questions, and the answers are stored in a two-dimensional array. Each row records a student’s answers to the questions, as shown in the following array.

                                

The key is stored in a one-dimensional array:

                    

Your program grades the test and displays the result. It compares each student’s answers with the key, counts the number of correct answers, and displays it.

程序如下:

import java.util.Scanner;public class GMCT{	public static void main(String[] args)	{		char answer[][] =		{				{'A','B','A','C','C','D','E','E','A','D'},				{'D','B','A','B','C','A','E','E','A','D'},				{'E','D','D','A','C','B','E','E','A','D'},				{'C','B','A','E','D','C','E','E','A','D'},				{'A','B','D','C','C','D','E','E','A','D'},				{'B','B','E','C','C','D','E','E','A','D'},				{'B','B','A','C','C','D','E','E','A','D'},				{'E','B','E','C','C','D','E','E','A','D'}		};				char keys[] = {'D','B','D','C','C','D','A','E','A','D'};		int[] student = new int[answer.length];		for(int i = 0; i < answer.length; ++i)		{			int right = 0;			for(int j = 0; j < answer[i].length; ++j)			{				if(answer[i][j] == keys[j])					++right;			}			student[i] = right;		}		for(int i = 0; i < student.length; ++i)			System.out.println("student"+(i+1)+"个学生回答正确"+student[i]+"个");	}}

运行的结果如下:

转载地址:https://blog.csdn.net/Zzehao11/article/details/106432764 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Java程序练习:类与方法、Swing组件
下一篇:Python实验:字典与集合的应用、函数的应用

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年04月09日 12时02分32秒