我想按照降序對6個作業成績的給定輸入進行排序,現在輸入是從文件中提取的,它由以下格式的成績組成 例如: hw1 hw2 hw3 HW4 hw5 hw6 學生1 50 30 40 10 30 0 學生2 12 20 30 12 30 40 學生3 12 50 60 10 20 30按照降序對整數進行排序而不使用數組
我已經寫正確的代碼取輸入,並保存在所述等級變量hw1
,其中所有學生都有hw1
等級,等等等等。
我也寫了一個代碼來排序hw的成績,但有一些問題與它有任何幫助,將不勝感激,據我所知在排序代碼之前我的while
循環中有問題。
double t2,t1,q1,q2,hw1,hw2,hw3,hw4,hw5,hw6,Final;
String Last_Name,First_Name;
int HW_Count=0;
Scanner input=new Scanner(System.in);
Scanner inData=new Scanner(System.in);
File inFile=new File("grades1.txt");
boolean inFileFound = false;
try {
input=new Scanner(inFile);
inFileFound=true;
}
catch(FileNotFoundException fnf) {
System.out.println("File not found");
}
while(inFileFound&&input.hasNextLine()) {
Last_Name=input.next();
t1=input.nextDouble();
t2=input.nextDouble();
Final=input.nextDouble();
hw1=input.nextDouble();
hw2=input.nextDouble();
hw3=input.nextDouble();
hw4=input.nextDouble();
hw5=input.nextDouble();
hw6=input.nextDouble();
q1=input.nextDouble();
q2=input.nextDouble();
HW_Count=input.nextInt();
First_Name=input.nextLine();
double t1final=t1*10/100;
double t2final=t2*15/100;
double Finalfinal=Final*25/200;
double q1final=q1*1/10;
double q2final=q2*1/10;
double finalgrade=0;
double temp=0;
while((hw1<hw2)||(hw2<hw3)||(hw3<hw4)||(hw4<hw5)) {
if(hw1<hw2) {
temp=hw1;
hw1=hw2;
hw2=temp;
}
if(hw2<hw3) {
temp=hw2;
hw2=hw3;
hw3=temp;
}
if(hw3<hw4) {
temp=hw3;
hw3=hw4;
hw4=temp;
}
if(hw4<hw5) {
temp=hw4;
hw4=hw5;
hw5=temp;
}
if(hw5<hw6) {
temp=hw5;
hw5=hw6;
hw6=temp;
}
}
}
添加||(hw5