Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

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.

nickleme06nickleme06 Posts: 1Member
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();

System.out.println();
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: ");
System.out.println();
finalScore = Integer.toString(score);

}
Arrays.sort(studentArray);
System.out.println(lastName + ", " + firstName + ": " + score);
sum += score;
average = sum/numberOfStudents;
System.out.println("Class Average =" + average);
}
Sign In or Register to comment.