java编程一个可以 进行多个选择题测验成绩(从高到低依次输出学生下标和成绩(可以重复))
作者:互联网
成绩可重复,从高到低输出,不会重复输出
public class GradeExam
{
public static void main(String[] args)
{
char[][] answers = {
{'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[] a=new int [8];
for(int i=0;i<answers.length;i++)
{
int j=0;
for(j=0;j<answers[i].length;j++)
{
if(answers[i][j]==keys[j])
//correctCount++;
a[i]++;//统计成绩
}
}
int[] b=new int [a.length];//定义另一个数组,以便后面对照
int i=0;
int j=0;
for(i=0;i<a.length;i++)
{
b[i]=a[i];//给b数组赋值且不排序
}
java.util.Arrays.sort(a);//对成绩数组a排序
for(i=a.length-1;i>=0;i--)
{
if(i!=0)
{
if(a[i]==a[i-1])
continue;
}//遇到重复成绩直接跳过本循环,以免重复输出
for(j=0;j<a.length;j++)
{
if(a[i]==b[j])//a,b数组对照
{
System.out.println("Student"+j+"'s correct count is"+a[i]); //输出学生下标和成绩
}
}
}
}
}
标签:输出,java,int,char,重复,高到,成绩 来源: https://blog.51cto.com/14233078/2374482