java等级_java编写成绩等级,最高分为best

题目:编写一个程序,读入学生成绩,获取最高分为best,然后其他等级值:

分数>=best-10,等级为A

分数>=best-20,等级为B

分数>=best-30,等级为C

分数>=best-40,等级为D

其他情况为F

import java.util.Scanner;

public class Grade

{

public static void main(String[] args)

{

System.out.print("请输入学生人数:");

Scanner input=new Scanner(System.in);

int n=input.nextInt();//输入学生人数

System.out.print("请输入学生的成绩:");

double[] student=new double[n];

for(int i=0;i

{

student[i]=input.nextDouble();//输入成绩

}

for(int i=0;i

{

System.out.println("Student"+i+"score is"+student[i]+"and grade is"+fac(i,n,student));

}

}

public static char fac(int j,int ren,double[] student)//等级划分函数fac

{

double best=max(ren,student);

if(student[j]>=best-10)

return 'A';

else if(student[j]>=best-20)

return 'B';

else if(student[j]>=best-30)

return 'C';

else if(student[j]>=best-40)

return 'D';

else

return 'F';

}

public static double max(int n,double[] student)//求最高分函数max

{

double max=student[0];

for(int i=1;i

{

if(max>student[i])

max=max;

else

max=student[i];

}

return max;

}

}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值