zoukankan      html  css  js  c++  java
  • 显示学生姓名及成绩降序排列

    显示学生姓名及成绩降序排列

    代码如下:

    package Day05;

    import java.util.Scanner;

    public class TestStudent {
    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    System.out.println("Enter student number: ");
    int stuNum = Integer.parseInt(sc.nextLine());
    Student[] stu = new Student[stuNum];
    for (int i = 0; i < stu.length; i++) {
    System.out.println("Enter student " + i + "'s name: ");
    String name = sc.nextLine();
    System.out.println("Enter student " + i + "'s score: ");
    double score = Double.parseDouble(sc.nextLine());
    stu[i] = new Student(name, score);
    }
    arrangeStudent(stu);
    printStudent(stu);
    } private static void printStudent(Student[] stu) {
    for (int i = 0; i < stu.length; i++) {
    System.out.println(stu[i].toString());
    }
    } private static void arrangeStudent(Student[] stu) {
    for (int i = 0; i < stu.length; i++) {
    for (int j = i + 1; j < stu.length; j++) {
    if (stu[i].getScore() < stu[j].getScore()) {
    Student tempStu = null;
    tempStu = stu[i];
    stu[i] = stu[j];
    stu[j] = tempStu;
    }
    }
    }
    }
    }

    只相信苦尽甘来
  • 相关阅读:
    错位排序
    不容易系列之(4)——考新郎
    大数乘法
    神、上帝以及老天爷(错位排序)
    学生成绩……
    蛇形矩阵
    topcoder
    进制转换
    问题 1011
    topcoder 针对C程序员的TopCoder C++ (快速掌握)_ixigua—仅有杀毒软件是不够的…… .
  • 原文地址:https://www.cnblogs.com/F001li/p/7055788.html
Copyright © 2011-2022 走看看