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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年04月09日 12时02分32秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
超过256的像素值的保存
2019-04-29
middle-判断二分图-深度优先和广度优先
2019-04-29
二进制补码和原码的记录
2019-04-29
双指针-二分-167. 两数之和 II - 输入有序数组
2019-04-29
双指针-45. 反转字符串中的元音字母
2019-04-29
双指针--环形链表
2019-04-29
python 模块化__init__.py-------__all__
2019-04-29
无重叠区间+用最少数量的箭引爆气球
2019-04-29
买卖股票的最佳时机
2019-04-29
非递减数列
2019-04-29
AUC粗浅理解笔记记录
2019-04-29
分治法:241. 为运算表达式设计优先级
2019-04-29
广度优先遍历:二进制矩阵中的最短路径
2019-04-29
广度优先遍历:set集合的速度远远比list快:完全平方数
2019-04-29
广度+深度:岛屿的最大面积/岛屿数量
2019-04-29
torch 模型运行时间与forward没对应的可能原因
2019-04-29
130. 被围绕的区域
2019-04-29
欧式距离、余弦相似度和余弦距离
2019-04-29
transform 等效转换(参考源码)
2019-04-29
cv2 PIL区别笔记
2019-04-29