閱讀以下說(shuō)明和Java代碼,將應(yīng)填入 (n) 處的語(yǔ)句或語(yǔ)句成分寫(xiě)在答題紙的對(duì)應(yīng)欄內(nèi)。
【說(shuō)明】
某數(shù)據(jù)文件students.txt的內(nèi)容為100名學(xué)生的學(xué)號(hào)和成績(jī),下面的程序?qū)⑽募械臄?shù)據(jù)全部讀入對(duì)象數(shù)組,按分?jǐn)?shù)從高到低進(jìn)行排序后選出排名前30%的學(xué)生。
【Java代碼】
import java.io.*;
class Student {
private String sNO; //學(xué)號(hào)
private int Credit; //分?jǐn)?shù)
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 descending 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(); //每次讀取一個(gè)學(xué)生的學(xué)號(hào)和成績(jī)
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; //學(xué)生總數(shù)
}
10年專(zhuān)注信管,信管教育專(zhuān)注者,信管網(wǎng)優(yōu)勢(shì)
免費(fèi)試聽(tīng)信管網(wǎng)信息系統(tǒng)項(xiàng)目管理師課程
全國(guó)前50名高分學(xué)員訪(fǎng)談:董麗(174)、李思...
信息系統(tǒng)項(xiàng)目管理師高端班培訓(xùn)課程
信管老師100小時(shí)直播課程
軟考報(bào)名專(zhuān)題(報(bào)名時(shí)間、入口等)
中級(jí)系統(tǒng)集成項(xiàng)目管理工程師通關(guān)課程
系統(tǒng)規(guī)劃與管理師課程(考試介紹與題型分析)
軟題庫(kù):軟考在線(xiàn)題庫(kù)、支持手機(jī)答題