java - I'm attempting to fill an array with the 20 most-recent user inputs. When I print the array the wrong ints are ouput -


i working on simple game assignment, complete aside part cannot seem right. game must fill array 20 recent moves, , print along total of number of moves once game over. example, user might make 25 moves, moves 6 - 25 printed. array length must == 20. insert relevant methods:

    public void fillmovestore(int [] array, int into) {     if (movecount <= array.length)     {         array[movecount - 1] = into;     }     else     {         for(int = 1; <= (array.length - 1); i++)         {             array[i] = array[i - 1];         }         array[array.length - 1] = into;     }    }  public void displaymoves(int [ ] array) {     for(int = 0; <= (array.length -2); i++)     {         system.out.print(array[i] + outputtext[34]);     }     system.out.print(array[array.length - 1] + outputtext[33]); } 

aside this, movecount incremented before fillmovestore(movestore, walkinto) called. new java... or hints appreciated! if more information required let me know, in advance

the problem line

array[i] = array[i - 1]; 

you've got backwards. you're supposed move elements down make room @ end of array, instead you're moving them up. try reversing it.

array[i-1] = array[i]; 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -