For loop 我必须使用for循环编写findStudentWithMaxGPA()方法,但我一直无法确定该怎么做。

For loop 我必须使用for循环编写findStudentWithMaxGPA()方法,但我一直无法确定该怎么做。,for-loop,For Loop,我必须编写一个findStudentWithMaxGPA()方法来遍历 数组,并返回具有最大值的学生名称 GPA。 但是,我不知道如何使用for循环来实现这一点 public class P4CRoster { private String name; private P4C[] students; public P4CRoster( ) { students = new P4C[3]; students[0

我必须编写一个findStudentWithMaxGPA()方法来遍历 数组,并返回具有最大值的学生名称 GPA。 但是,我不知道如何使用for循环来实现这一点

public class P4CRoster
    {
    private String name;
    private P4C[] students;
    public P4CRoster( )
        {
          students = new P4C[3];
          students[0] = new P4C("Hieu Tran", 4.0, 4.0, 4.0, 4.0, 4.0);
          students[1] = new P4C("Steven Nguyen", 3.5, 3.5, 3.5, 3.5, 3.5);
          students[2] = new P4C("Saul Sanchez", 3.0, 3.0, 3.0, 3.0, 3.0);
        }//end method
    public double findStudentWithMaxGPA()
        {
           double x = students[0].calcGPA();
           double y = students[1].calcGPA();
           double z = students[2].calcGPA();

           x.compareTo(y);
           x.compareTo(z);
           y.compareTo(z);
        }//end method
    public String toString()
        {
           String output = new String();
           output = "The Student with the max GPA is: " + findStudentWithMaxGPA;
           return output;
        }//end toString
}

知道数组中正好有3个元素,可以不使用循环来完成吗?我看到一些对
compareTo
的调用,但您对它们的结果不做任何处理。请至少指定语言…语言为Java知道数组中正好有3个元素,可以不使用循环来执行吗?我看到一些调用
compareTo
,但您对它们的结果不做任何处理。请至少指定语言…语言是Java