You have to avoid using arrays in this situation. It's better to create a class for the student and collect all data there. Remember, you can treat an array as an object with not changeable length.
class Student {
private final String name;
private int mathsMark;
private int scienceMarks;
}
Student A = new Student("A", 95, 80);
Student B = new Student("B", 50, 75);
Student C = new Student("C", -1, -1);
Student D = new Student("D", 80, 90);
Student E = new Student("E", -1, -1);
Student[] students = { A, B, C, D, E};
In case you want to collect and then add/remove students, it is better to use a Map:
Map<String, Student> map = new HashMap<>();
map.put(A.getName(), A);
map.put(B.getName(), B);
map.put(C.getName(), C);
map.put(D.getName(), D);
map.put(E.getName(), E);
map.remove(C.getName());
map.remove(E.getName());
In case you still want to use an arrays, this is the solution
public static void main(String... args) throws IOException {
String[] students = { "A", "B", "C", "D", "E" };
int[] mathsMarks = { 95, 50, -1, 80, -1 };
int[] scienceMarks = { 80, 75, -1, 90, -1 };
assert mathsMarks.length == scienceMarks.length;
int length = students.length;
for (int i = 0; i < mathsMarks.length; i++)
if (mathsMarks[i] < 0 || scienceMarks[i] < 0)
length--;
String[] newStudents = new String[length];
int[] newMathsMarks = new int[length];
int[] newScienceMarks = new int[length];
for (int i = 0, j = 0; i < mathsMarks.length; i++) {
if (mathsMarks[i] >= 0 && scienceMarks[i] >= 0) {
newStudents[j] = students[i];
newMathsMarks[j] = mathsMarks[i];
newScienceMarks[j] = scienceMarks[i];
j++;
}
}
System.out.println(Arrays.toString(newStudents));
System.out.println(Arrays.toString(newMathsMarks));
System.out.println(Arrays.toString(newScienceMarks));
}