Array not printing properly [closed]

Use this loop:

 for (int i = prevScore.length; i > 0; i--){
    System.out.println(prevScore[i-1] + " " + prevScoreName[i-1]);

}

I think it should solve your problem.

Update

based on your updated program. Move the following code above the start of the ‘do’ loop.

    int [] prevScore = new int[] { 0 };

   String [] prevScoreName = new String[] {"John Doe"};

That is you are moving these lines out of the loop. It should work now.

That is the start of your ‘main’ method should look something like this:

 public static void main(String args[]) throws IOException {
        int press = 0;
        int[] prevScore = new int[] { 0 };

        String[] prevScoreName = new String[] { "John Doe" };
        do {
            int menuchoice = 0;

            System.out.println("Menu choice: 1 to start game, 2  print instructions," + "3 prev score");

Leave a Comment