栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Java语言程序设计 例题7.1(指定等级)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Java语言程序设计 例题7.1(指定等级)

*7.1 (Assign grades) Write a program that reads student scores, gets the best score, 
and then assigns grades based on the following scheme:
Grade is A if score is >= best - 10
Grade is B if score is >= best - 20;
Grade is C if score is>=best - 30;
Grade is D if score is>= best - 40;
Grade is F otherwise.
The program prompts the user to enter the total number of students, then prompts 
the user to enter all of the scores, and concludes by displaying the grades. Here 
is a sample run:
Enter the number of students: 4
Enter 4 scores: 40 55 70 58
Student 0 score is 40 and grade is C
Student 1 score is 55 and grade is B
Student 2 score is 70 and grade is A
Student 3 score is 58 and grade is B

*7.1(指定等级)编写一个程序,读取学生的分数,获取最高分,然后根据以下方案分配分数:

Grade is A if score is >= best - 10
Grade is B if score is >= best - 20;
Grade is C if score is>=best - 30;
Grade is D if score is>= best - 40;

程序提示用户输入学生总数,然后提示用户输入所有分数,最后显示成绩,下面是一个例子:

Enter the number of students: 4
Enter 4 scores: 40 55 70 58
Student 0 score is 40 and grade is C
Student 1 score is 55 and grade is B
Student 2 score is 70 and grade is A
Student 3 score is 58 and grade is B

代码如下:

import java.util.Scanner;
public class Unite7Test1 {
	public static void main(String[] args) 
	{
		Scanner scan=new Scanner(System.in);
		System.out.println("Enter the number of students : ");
		int num=scan.nextInt();
		System.out.println("Enter  "+num+"  scores :");
		int max=0;
		int arr[]=new int[num];
		for(int i=0;imax) 
			{
				max=score;
			}
			
		}
		for(int i=0;i=max-10) 
			{
				System.out.println("Student  "+i+"  score  is "+arr[i]+"and grade is  A" );
			}else if(arr[i]>=max-20) 
			{
				System.out.println("Student  "+i+"  score  is "+arr[i]+"and grade is  B" );
			}else if(arr[i]>=max-30) 
			{
				System.out.println("Student  "+i+"  score  is "+arr[i]+"and grade is  C" );
			}else if(arr[i]>=max-40) 
			{
				System.out.println("Student  "+i+"  score  is "+arr[i]+"and grade is  D" );
			}else {
				System.out.println("Student  "+i+"  score  is "+arr[i]+"and grade is  F" );
			}
		}

	}
	
}

结果如下:

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/894636.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号