したがって、リストのすべての値をチェックして、最大のものを返す必要があります (listsize は、以前に宣言した変数で、リストのサイズです)。これは、見た目よりも難しいことが証明されています。これにより、常にリスト内の特定の場所に値が表示されます...何が問題なのですか?
package act9;
import java.util.Scanner;
public class Act9 {
public static void main(String[] args) throws InterruptedException{
Scanner input = new Scanner(System.in);
String[] listnames = null;
int[] listgrades = null;
int size = 0;
System.out.println("How many students in your class? ");
try {
size = input.nextInt();
if(size<=30) {
listnames = new String[size+1];
listgrades = new int[size+1];
}
else if(size>30) {
System.out.println("The maximum class size is 30, didn't you know?");
}
}catch(Exception e) {
System.out.println("This needs to be a number, please. Jesus, how dense.");
System.exit(0);
}
try {
for(int c=0; c<size; c++) {
System.out.println("Give the [first] name of a student:");
listnames[c] = input.next();
System.out.println("What was their final grade?");
listgrades[c] = input.nextInt();
}
}catch (Exception f) {
System.out.println("Did you correctly type the name and grade? you're so dumb I think I'll stop the program right here.");
System.exit(0);
}
System.out.println("Out of your group of " + size + "students, this were their scores;");
System.out.println("");
System.out.println("name | grade");
System.out.println("____________________________________");
for(int c2=0; c2<size; c2++) {
System.out.println(listnames[c2] + " | " + listgrades[c2]);
Thread.sleep(100);
}
int temp = 1;
int d = 0;
for (d=0 ; d<size; d++) {
}
if(Math.max(listgrades[d],listgrades[temp])==listgrades[d]) {
temp = d;
}
else {
//temp=temp. That's what nothingness means
}
System.out.println("Your student with the highest grade is " + listnames[temp] + " with a grade of " + listgrades[temp] + " points. Well Done.");
}
}
これは完全なコードですが、少し複雑です (アイデアは、教室が何とか何とか何とかなるということです。成績、何でも。それは私が理解できない一種の課題です)