Java 如何从多维数组中提取值?

Java 如何从多维数组中提取值?,java,arrays,loops,Java,Arrays,Loops,使用多维数组对我来说是第一次,所以我对这些数组的一些方面的理解有点…模糊。现在快速回顾一下这个程序完成后将用于什么 它将允许老师输入一个学生的名字和四个相应的考试分数。他们最多可以列出15名学生 约翰·史密斯:67 75 84 52 无名氏:54868179 填写完firstNameField、lastNameField和test1Field-test4Field后,按下add按钮,该按钮在另一个字段中输出它,并输出您添加的每个学生,创建一个列表 我的问题是找到班级平均水平。我只想找出每个学生的

使用多维数组对我来说是第一次,所以我对这些数组的一些方面的理解有点…模糊。现在快速回顾一下这个程序完成后将用于什么

它将允许老师输入一个学生的名字和四个相应的考试分数。他们最多可以列出15名学生

约翰·史密斯:67 75 84 52 无名氏:54868179

填写完firstNameField、lastNameField和test1Field-test4Field后,按下add按钮,该按钮在另一个字段中输出它,并输出您添加的每个学生,创建一个列表

我的问题是找到班级平均水平。我只想找出每个学生的四个测试分数(而不是名字),我会创建一个等式来找到平均值,这很容易。问题是,我不确定是谁从数组中取出所有的测试分数,这样我就可以这样做了

public class StudentGradesView extends FrameView {

    int [][] aryStudent = new int [15][4]; // [15] being # of students, [4] for test scores
    String[] studentNames = new String[15]; //this isn't being used now...
    int numOfStudents = 0; //listing the students starts off from 0...

    int marks = 0; //might be needed for grabbing out test scores for finding average?

    int test1;
    int test2;
    int test3;
    int test4;

    public StudentGradesView(SingleFrameApplication app) {

//unimportant...for GUI...

}
    private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {                                          

        aryStudent[numOfStudents][0] = Integer.parseInt(test1Field.getText());
        aryStudent[numOfStudents][1] = Integer.parseInt(test2Field.getText());
        aryStudent[numOfStudents][2] = Integer.parseInt(test3Field.getText());
        aryStudent[numOfStudents][3] = Integer.parseInt(test4Field.getText());

        StringBuilder sb = new StringBuilder();


//The following is the code that list the students and their grades...this code should be fine..

        for (int x=0; x <= numOfStudents && x<15; x++) {
            sb.append(firstNameField.getText() + " " + lastNameField.getText());
            for (int y=0; y < 4; y++) {
                sb.append(" " +aryStudent[x][y]);
           // studentListField.setText("" + firstNameField.getText() + " " + lastNameField.getText() + " " + aryStudent[numOfStudents][y] + "\n" + currentList);
            }
            sb.append("\n");
        }
        studentListField.setText(sb.toString());
        numOfStudents ++;
    }                                         

    private void classAverageButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                   
public class StudentGradesView扩展了FrameView{
int[]aryStudion=new int[15][4];/[15]是学生中的一员,[4]表示考试成绩
String[]studentNames=新字符串[15];//现在不使用此字符串。。。
int numOfStudents=0;//列出学生从0开始。。。
int marks=0;//可能需要获取考试分数才能找到平均分?
int test1;
int test2;
int test3;
int test4;
公共学生成绩视图(SingleFrameApplication应用程序){
//不重要…对于GUI。。。
}
私有void addButtonActionPerformed(java.awt.event.ActionEvent evt){
aryStudent[numOfStudents][0]=Integer.parseInt(test1Field.getText());
aryStudent[numOfStudents][1]=Integer.parseInt(test2Field.getText());
aryStudent[numOfStudents][2]=Integer.parseInt(test3Field.getText());
arystustudent[numOfStudents][3]=Integer.parseInt(test4Field.getText());
StringBuilder sb=新的StringBuilder();
//以下是列出学生及其成绩的代码…此代码应该可以。。

对于(int x=0;x您的代码几乎是正确的——不过,您只需要一个for循环

for(int x = 0; x < numOfStudents && x<15; x++) {
  averageField.setText((aryStudent[x][0] + aryStudent[x][1] + aryStudent[x][2] + [aryStudent[x][3])/4);
}
for(int x=0;xfor(int x = 0; x < numOfStudents && x<15; x++) {
  averageField.setText((aryStudent[x][0] + aryStudent[x][1] + aryStudent[x][2] + [aryStudent[x][3])/4);
}