Reputation: 45
my program is basically a gradebook in the form of an array and values are stored in that array. I think it's better if I show you what my program does once it's run.
As you can see it runs successfully however I'm trying to display all the of the elements (grades) stored in my array (Grade book) after the final grade has been entered. So in this test run I've entered 4 grades, but I've set up my code in a way that after it's run, it displays the every grade in the grade book after each grade is entered RATHER than after the final grade is entered depending on the number of grades that need to enetered. Here is my code:
import java.lang.reflect.Array;
import java.util.Scanner;
public class GradeBooks {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
gradesentered(input);
}
public static void gradesentered(Scanner input) {
int grades = NumberReader.readPositiveInt(input, "Please enter the number of grades: ",
"Error: Invalid data entered");
Any suggestions would be greatly appreciated. :)
Upvotes: 1
Views: 285
Reputation: 45
Thank you JB Nizet.
I moved
System.out.println("The Grade book contains: ");
printArray(mogrades);
outside of my for-loop
Upvotes: 1
Reputation: 61
JB Nizet is correct. Just move printArray(mogrades); Outside the loop.
Upvotes: 0