Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
Getting variable array to hold information.
I am trying to do an array with a variable length. This array also accepts user input. when I try to print out the array all I am getting is the last student entered. Any suggestions. Here is my code for my array.
int numberOfStudents = getStudentCount();
studentArray = new Student [numberOfStudents];
for (int i = 0; i < numberOfStudents; i++)
studentArray[i] = new Student(lastName, firstName, score);
lastName = getString("Student " + i + " Last Name: ");
firstName = getString("Student " + i + " First Name: ");
score = getScore("Student " + i + " score: ");
finalScore = Integer.toString(score);
System.out.println(lastName + ", " + firstName + ": " + score);
sum += score;
average = sum/numberOfStudents;
System.out.println("Class Average =" + average);
0 · ·