当前位置: 答题翼 > 问答 > 计算机类考试 > 正文
目录: 标题| 题干| 答案| 搜索| 相关
问题

试题六(共15分) 阅读以下说明和 Java 代码,将应填入 (n) 处的语句或语句成分写在答题纸的对应栏


试题六(共15分)

阅读以下说明和 Java 代码,将应填入 (n) 处的语句或语句成分写在答题纸的对

应栏内。

【说明】

某数据文件 students.txt的内容为100名学生的学号和成绩,下面的程序将文件中的

数据全部读入对象数组,按分数从高到低进行排序后选出排名前 30%的学生。

【Java代码】

import java.io.*;

class Student {

private String sNO; //学号

private int Credit; //分数

public int getCredit(){

return Credit;

}

public String toString() {

return "sNO = " + this.sNO + ", Credit = " + this.Credit;

}

Student(String sNO, int Credit){

(1) = sNO;

(2) = Credit;

}

}

public class SortStudent {

void sort(Student[] s) { //Sort the array s[] in decending order of Credit

for (int i = 0; i < s.length-1; i++) {

for (int j = i+1; j < s.length; j++) {

if (s[i]. (3) < s[j]. (4) ) {

Student tmp = s[i];

s[i] = s[j];

s[j] = tmp;

}

}

}

}

public static void main(String argv[]) {

Student[] testStudent = new Student[size];

try {

BufferedReader in = new BufferedReader(new FileReader("students.txt"));

boolean done = false;

int i = 0;

while (!done) {

String s = in.readLine(); //每次读取一个学生的学号和成绩

if (s != null) {

String tmp[] = s.split(",");

testStudent[i++] = (5) (tmp[0], Integer.parseInt(tmp[1]));

} else

done = true;

}

in.close();

(6) = new SortStudent();

ss.sort(testStudent);

System.out.println("top 30%:");

for (int j = 0; j < size * 0.3; j++)

System.out.println(testStudent[j]);

} catch (IOException e) {

System.out.println("io error!");

}catch (NumberFormatException e) {

System.out.println("not a number!");

}

}

(7) int size = 100; //学生总数

}

参考答案
您可能感兴趣的试题
  • 试题二(共 15分) 阅读以下说明和C函数,将应填入 (n) 处的字句写在答题纸的对应栏内。 【说明 1】 函

  • 试题五(共 15分) 阅读以下说明和C++代码,将应填入 (n) 处的字句写在答题纸的对应栏内。 【说明】 已

  • 试题六(共 15分) 阅读以下说明和Java代码,将应填入 (n) 处的字句写在答题纸的对应栏内。 【说明】

  • 试题六 (共15 分) 阅读以下说明和Java代码,将应填入 (n) 处的字句写在答题纸的对应栏内。 【 说明

  • 试题二(共15分)阅读以下说明、C程序代码和问题1至问题3,将解答写在答题纸的对应栏内。【说明1】设在

  • 试题二(共15分)阅读以下说明和C函数,填充函数中的空缺,将解答填入答题纸的对应栏内。【说明】如果矩