Java implements the input of multiple students' grades, and judges grades, total scores, average scores, maximum values, and minimum values

Table of contents

I. Introduction

Two, the code segment

 3. Program running results (console output) 

4. Codes of knowledge points involved


I. Introduction

1. This code was written by me when I was in school. There are some places that have not been perfectly implemented. Please forgive me and give me more advice!

2. This pop-up window interface can be input according to simple requirements, and display whether the result is the result. The code setting of this article is to realize the input of multiple students' grades, and judge the grade, total score, average score, maximum value, and minimum value. At the same time, custom settings can be realized;

3. This is a loop nested statement, which requires the use of for and if else statements. This program is set to enter the grades of 5 students in order to realize the corresponding judgment;

4. The system can only run on the console (eclipse and other versions), and needs to be matched with the jdk environment;

5. Here is a special note, if the complete code package name to be pasted is inconsistent with mine, it is specified inconsistently, please change it manually;

Two, the code segment

1. Code segment 

package exam.package14;

import java.util.Scanner;

public class Test01 {

	public static void main(String[] args) {
		// TODO 自动生成的方法存根
	

		int sum=0;
		float avg=0;
		Scanner in=new Scanner(System.in);
        int score[]=new int[5];
        for (int i = 0; i <score.length; i++) {
        	System.out.println("您输入第"+(i+1)+"名同学的成绩");
        	score[i]=in.nextInt();
            if (score[i]< 0 || score[i]> 100) {
                System.out.println("您输入的数据是一个非法数据");
            } else if (score[i]<60) {
                System.out.println("不及格");
            } else if (score[i] < 70) {
                System.out.println("及格");
            } else if (score[i]< 80) {
                System.out.println("中等");
            } else if (score[i]< 90) {
                System.out.println("良好");
            } else {
                System.out.println("优秀");
            }
            sum+=score[i];
        }
        double Max=score[0];
		double Min=score[0];
        for (int i=1; i<score.length;i++) {
			if (Max<score[i]) {
				Max=score[i];
			}
		}
        for (int i=1;i<score.length;i++) {
			if (Min>score[i]) {
				Min=score[i];
			}
		}
		
        avg=sum/5.0f;
        System.out.println("这五名学生总分为:" + sum);
        System.out.println("这五位同学的平均成绩为:" + avg);
        System.out.println("最高分是:" + Max);
		System.out.println("最低分是:" + Min);
    }
}

 3. Program running results (console output) 

1. The display result when entering the grade of the first student 

2. Display results after inputting (5) student grades 

4. Codes of knowledge points involved

1. Loop nested statement

 for (int i=1; i<score.length;i++) {
            if (Max<score[i]) {
                Max=score[i];
            }
        }

Guess you like

Origin blog.csdn.net/weixin_59042297/article/details/129783864