JAVA使用数组存储输入的成绩并对成绩分段打分------JAVA入门基础教程

System.out.println("请输入成绩有几个");
int sc = in.nextInt();
int[] scores = new int[sc];
//输入成绩
for(int i = 0;i < scores.length;i++)
{
    System.out.println("请输入成绩");
    scores[i] = in.nextInt();
}
//获取最大值
int bg = scores[0];
for(int i = 0;i < scores.length;i++)
{
    if(bg < scores[i])
    {
        bg = scores[i];
    }
}
System.out.println("最高分数"+bg);
//区分分段
char grade = 0;
for(int i = 0;i < scores.length;i++)
{
    if((bg - scores[i]) <= 10)
    {
        grade = 'A';
    }
    else if((bg - scores[i]) <= 20)
    {
        grade = 'B';
    }
    else if((bg - scores[i]) <= 30)
    {
        grade = 'C';
    }
    else
    {
        grade = 'D';
    }
    System.out.println(scores[i] + "分段是" + grade);
}

你可能感兴趣的:(JAVA随手写,java,算法,数据结构,eclipse,intellij-idea)