Coco
Coco

Reputation: 45

JAVA Properly formatting my grade book containing grades contained in array

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. enter image description here

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

Answers (2)

Coco
Coco

Reputation: 45

Thank you JB Nizet.

I moved

System.out.println("The Grade book contains: ");
printArray(mogrades);

outside of my for-loop

Upvotes: 1

S. Cassidy
S. Cassidy

Reputation: 61

JB Nizet is correct. Just move printArray(mogrades); Outside the loop.

Upvotes: 0

Related Questions