[20-05-01][Self-test 29]Java Pass or Fail

2021-02-01 13:17

阅读:460

标签:sel   lse   一个   nav   public   style   程序   main   统计学   

 1 package test_6_3;
 2 
 3 public class Student {
 4 
 5     /**
 6      * 编写一个程序,统计学生成绩,其功能包括输入学生的姓名和成绩,
 7      * 按成绩从高到低排列打印输出,对前%70的学生定为合格(PASS),而后30%的学生定为不合格(FAIL)
 8      */
 9     
10     public String name;
11     public int score;
12     
13     public Student(String name, int score) {
14         
15         this.name = name;
16         this.score = score;
17     }
18     
19 }

 

 1 package test_6_3;
 2 
 3 public class Deal {
 4     
 5     public void sort(Student[] students) {
 6         
 7         for (int i = 0; i ) {
 8             for (int j = i + 1; j ) {
 9                 if (students[i].score  students[j].score) {
10                     Student temp = students[i];
11                     students[i] = students[j];
12                     students[j] = temp;
13                 }
14             }
15             
16         }
17     
18     }
19 
20     public void deal(Student[] students) {
21         
22         sort(students);
23         
24         for (int i = 0; i ) {
25             
26             if (i + 1 ) {
27                 System.out.println("姓名:" + students[i].name + ",成绩:" + students[i].score + ",PASS");
28             } else {
29                 System.out.println("姓名:" + students[i].name + ",成绩:" + students[i].score + ",FAIL");
30             }
31         }
32     }
33 
34 }

 

 1 package test_6_3;
 2 
 3 public class Test {
 4 
 5     public static void main(String[] args) {
 6         
 7         Student[] students = new Student[5];
 8         
 9         students[0] = new Student("Joker", 90);
10         students[1] = new Student("Navi", 100);
11         students[2] = new Student("Violet", 90);
12         students[3] = new Student("Skull", 20);
13         students[4] = new Student("Panther", 80);
14         
15         Deal deal = new Deal();
16         
17         deal.deal(students);
18 
19     }
20 
21 }

 

结果如下:

姓名:Navi,成绩:100,PASS
姓名:Joker,成绩:90,PASS
姓名:Violet,成绩:90,PASS
姓名:Panther,成绩:80,FAIL
姓名:Skull,成绩:20,FAIL

[20-05-01][Self-test 29]Java Pass or Fail

标签:sel   lse   一个   nav   public   style   程序   main   统计学   

原文地址:https://www.cnblogs.com/mirai3usi9/p/12813362.html

上一篇:归并排序算法

下一篇:推荐算法简介


评论


亲,登录后才可以留言!