一个简单的计算分数的小程序
代码如下:
package Day05; public class ExamGradeDemo {
public static void main(String[] args) {
char[][] answers = {
{‘C‘,‘B‘,‘D‘,‘C‘,‘A‘,‘A‘,‘D‘,‘C‘,‘D‘,‘C‘},
{‘A‘,‘C‘,‘B‘,‘D‘,‘C‘,‘A‘,‘D‘,‘C‘,‘B‘,‘D‘},
{‘A‘,‘C‘,‘B‘,‘D‘,‘B‘,‘D‘,‘C‘,‘A‘,‘A‘,‘D‘},
{‘A‘,‘C‘,‘B‘,‘D‘,‘C‘,‘A‘,‘A‘,‘D‘,‘C‘,‘C‘},
{‘A‘,‘C‘,‘D‘,‘C‘,‘A‘,‘A‘,‘D‘,‘D‘,‘C‘,‘A‘},
{‘A‘,‘C‘,‘B‘,‘D‘,‘C‘,‘A‘,‘A‘,‘D‘,‘C‘,‘A‘},
{‘A‘,‘C‘,‘B‘,‘D‘,‘C‘,‘A‘,‘A‘,‘D‘,‘C‘,‘C‘},
{‘A‘,‘C‘,‘B‘,‘D‘,‘C‘,‘A‘,‘D‘,‘C‘,‘A‘,‘A‘}
};
char[] keys = {‘A‘,‘B‘,‘D‘,‘C‘,‘A‘,‘A‘,‘D‘,‘C‘,‘D‘,‘A‘};
for (int row = 0; row < answers.length; row++) {
int correctCount = 0;
for (int col = 0; col < answers[row].length; col++) {
if (answers[row][col] == keys[col]) {
correctCount++;
}
}
System.out.println("Student " + row + "‘s score is " + correctCount);
}
}
}