IO流 學生成績記錄練習題

2022-09-09 10:57:15 字數 1961 閱讀 8277

從score.txt檔案中讀取資料,檔案中每行是乙個學生的成績記錄,

內容格式為:

姓名、英語成績、語文成績、數學成績、j**a成績。

要求:按總分從高到低排序後顯示出每個學生的各科成績和總成績。

score.txt檔案內容例如:

姓名##英語##語文##數學##j**a

羅霄##68##95##52##81

劉苗苗##97##97##84##62

郝笑##75##93##87##52

李昊陽##86##83##88##68

雷鳴##54##73##70##91

李文龍##79##97##96##63

趙璧輝##52##51##75##97

姜治文##59##88##60##86

陳琳##86##53##58##63

蘇浩##79##68##89##55

李金洲##61##89##72##71

王歡##82##66##86##70

王璐##68##60##84##70

public static void main(string args) throws ioexception 

studentdemo atu = new studentdemo[num - 1];//建立乙個學生類陣列用於儲存學生資訊

/*獲取每個學生的資訊

*/filereader fread = new filereader("d:\\score.txt");

bufferedreader bread = new bufferedreader(fread);

bread.readline(); // 讀取第一行,為後面讀取的每行都是學生的資訊

string s = null;

int count = 0;

while ((s = bread.readline()) != null)

//分別對應 姓名 英語 語文 數學 j**a

studentdemo stu = new studentdemo(infor[0], score[0], score[1], score[2], score[3], sum); // 儲存每次讀取的一位同學的所有資訊

atu[count] = stu;

count++;

}arrays.sort(atu);//在student類中重寫了compare方法,使用總成績排序

//遍歷輸出

for (studentdemo i : atu)

}

public class studentdemo implements comparable

public string getname()

public void setname(string name)

public int getenglish()

public void setenglish(int english)

public int getmath()

public void setmath(int math)

public int getchinese()

public void setchinese(int chinese)

public int getj**as()

public void setj**as(int j**as)

public int getnum()

public void setnum(int num)

@override

public string tostring() ';

}@override

public int compareto(studentdemo o)

}

process finished with exit code 0

I O練習題 tee實現

tee命令是從標準輸入中讀取資料,直到檔案結尾,隨後將資料寫入標準輸出和命令列引數的檔案。使用i o 實現tec命令。預設情況下,若已存在於命令列引數指定檔案同名的檔案tec命令會將其覆蓋。如果檔案已存在,請實現 a tee a 在檔案結尾處追加資料。include include define m...

CCF 練習題201703 2 學生排隊

體育老師小明要將自己班上的學生按順序排隊。他首先讓學生按學號從小到大的順序排成一排,學號小的排在前面,然後進行多次調整。一次調整小明可能讓一位同學出隊,向前或者向後移動一段距離後再插入佇列。例如,下面給出了一組移動的例子,例子中學生的人數為8人。0 初始佇列中學生的學號依次為1,2,3,4,5,6,...

習題3 4 統計學生成績

本題要求編寫程式讀入n個學生的百分制成績,統計五分制成績的分布。百分制成績到五分制成績的轉換規則 輸入在第一行中給出乙個正整數n 1000 即學生人數 第二行中給出n個學生的百分制成績,其間以空格分隔。在一行中輸出a b c d e對應的五分制成績的人數分布,數字間以空格分隔,行末不得有多餘空格。7...