You need to do it using the regular for
loop with an index, like this:
if (marks.length != studentNames.length) {
... // Something is wrong!
}
// This assumes that studentNames and marks have identical lengths
for (int i = 0 ; i != marks.length ; i++) {
System.out.println(studentNames[i]);
System.out.println(marks[i]);
}
A better approach would be using a class to store a student along with his/her marks, like this:
class StudentMark {
private String name;
private int mark;
public StudentMark(String n, int m) {name=n; mark=m; }
public String getName() {return name;}
public int getMark() {return mark;}
}
for (StudentMark sm : arrayOfStudentsAndTheirMarks) {
System.out.println(sm.getName());
System.out.println(sm.getMark());
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…