Java入门级程序 :Problem: Grading a Multiple-Choice Test

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]+"个");
	}
}

运行的结果如下:

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值