private static String[]student no = new String[100];
private static int[]students core = new int[100];
公共靜態void main(String[] args) {
read dat();//隨機生成學號和學生成績。
print _ 1(studentcore,student no);//打印信息,以便按年級輸出時,比較學號與年級是否壹壹對應。
sort_(學生核心,學生編號);//按學生成績降序排序,對學號做相應轉換。
print _ 1(studentcore,student no);//輸出最終結果
}
/**
* @作者管理員
* @param
* @info隨機生成學號和學生成績。
*/
公共靜態void readDat() {
for(int I = 0;我& lt學生編號長度;i++) {
int number = new Random()。nextInt(100);
字符串numInfo//拼湊學號信息字符串
如果(數字& lt10) {
numInfo = " 0 "+number;//學號末尾的數字為1時,前面自動補零,組成2。嚴格來說,壹個班的學生人數不會超過100。
}否則{
numInfo = " "+number;
}
student no[I]= " 2013014012 "+numInfo;//拼湊學號,入學年份+部門代碼+班級代碼+學生班級號。
studentScore[i] = new Random()。nextInt(100);
}
}
/**
* @作者管理員
* @param studentScore
* @param studentNo
* @info按學生成績降序排序,對學號做相應轉換。采用氣泡排序原理進行排序。
*/
public static void sort _(int[]students core,String[] studentNo) {
if (studentScore.length!=學生編號長度){
嘗試{
Thrownnewexception("年級與學號數量不壹致,請核對信息");
} catch(異常e) {
e . printstacktrace();
}
} else {//冒泡排序
for(int I = 0;我& lt學生核心長度;i++) {
for(int j = 0;j & lt學生核心長度;j++) {
int temp = 0;//中間值變量
字符串變量;//中間值變量
if (studentScore[i]>學生核心[j]) {
temp =學生核心[I];
variable = student no[I];
學生核心[i] =學生核心[j];//年級變了,學號也會跟著變。
學生編號[i] =學生編號[j];
studentScore[j]= temp;
studentNo[j] =變量;
}
}
}
}
}
/**
* @作者管理員
* @param studentScore
* @param studentNo
* @info輸出按最終結果排序的相應信息。
*/
public static void print _ 1(int[]studentcore,String[] studentNo) {
if (studentScore.length!=學生編號長度){
嘗試{
Thrownnewexception("年級與學號數量不壹致,請核對信息");
} catch(異常e) {
e . printstacktrace();
}
}否則{
for(int I = 0;我& lt學生核心長度;i++) {
System.out.println("|學生ID: "+studentNo[i]+"\t"+"成績: "
+students core[I]);
}
}
}
}