标签:public and stat i++ util double main har student
题目:编写一个程序,读入学生成绩,获取最高分为best,然后其他等级值: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<n;i++)
{
student[i]=input.nextDouble();//输入成绩
}
for(int i=0;i<n;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<n;i++)
{
if(max>student[i])
max=max;
else
max=student[i];
}
return max;
}
}
标签:public and stat i++ util double main har student
原文地址:https://blog.51cto.com/14233078/2371824