我正在尝试让我的代码按从高到低的顺序显示名称和分数(由用户提供)。我的代码还显示最高等级,最低等级和平均等级。
但我不知道如何按顺序显示名称和分数。
这是我的代码:
<?php
include "conectarse.php";
//Obtener los datos de la pag web.
$usuario = $_POST['botonUser'];
$pass1 = $_POST['botonPass'];
//Procedo a conectarme a la Base de Datos
$link = conectarse($baseDatos);
$query_select = "SELECT * FROM usuarios WHERE usuario = '$usuario' AND pass = '$pass1';";
$registro = $link->query($query_select);
if($row = mysqli_fetch_array($registro))
{
session_start();
$_SESSION['nom'] = $row['nombre'];
$_SESSION['apellido'] = $row['apellido'];
$_SESSION['usuario'] = $row['usuario'];
$_SESSION['tiempo'] = strftime("Hoy es %A y son las %H:%M");
echo 'Si';
}
else {
session_start();
echo "No";
$_SESSION['nom'] = "Anonimo";
}
$link->close();
?>
代码完成后,它应该是这样的。我在括号中有所有内容:
import java.util.ArrayList;
import java.util.Scanner;
public class FinalGrades {
public static void main (String[] args) {
ArrayList<Integer> bestStudentPosition = new ArrayList<Integer>();
ArrayList<Integer> worstStudentPosition = new ArrayList<Integer>();
Scanner input = new Scanner(System.in);
System.out.print("How many students are in your class? ");
int totalStudents = Integer.parseInt(input.nextLine());
String[] names = new String[totalStudents];
double[] scores = new double[totalStudents];
double maxGrade = 0;
double minGrade = 0;
double avg = 0;
double sum = 0;
for (int i = 0; i < totalStudents; i++) {
System.out.print("Name: ");
names[i] = input.next();
System.out.print("Score: ");
scores[i] = input.nextDouble();
sum += scores[i];
if (i == 0) {
minGrade = scores[0];
}
if (scores[i] > maxGrade) {
bestStudentPosition.clear();
maxGrade = scores[i];
bestStudentPosition.add(new Integer(i));
} else if (scores[i] == maxGrade) {
bestStudentPosition.add(new Integer(i));
}
if (i > 0 && scores[i] < minGrade) {
worstStudentPosition.clear();
minGrade = scores[i];
worstStudentPosition.add(new Integer(i));
} else if (scores[i] == minGrade) {
worstStudentPosition.add(new Integer(i));
}
}
avg = sum / totalStudents;
System.out.print("Highest score: ");
for (Integer position : bestStudentPosition) {
System.out.println(maxGrade + ", " + names[position]);
}
System.out.print("Lowest score: ");
for (Integer position : worstStudentPosition) {
System.out.println(minGrade + ", " + names[position]);
}
System.out.printf("Average: %3.2f", avg);
}
}