You need to do this using a regular for loop with index, for example:
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 to use the class to store the student along with his / her signs, for example:
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()); }
source share