lundi 9 octobre 2023

I am trying to make a random shuffle of a deck of cards with an array but I need the answer to be reversed [duplicate]

I am trying to make a random shuffle of a deck of cards with an array but the answer that is printed out, I need to be reversed. The base code itself is fine and runs without error, but how do i reverse my result. For example, if it printed out 31, 42, 12, 26 right now, I need it to be reversed, so, 26, 12, 42, 31. Could someone help with this? Heres my code. Thanks much!

private static void randomShuffle(int[] cards, Random random)
    {
        // TODO implement
        random.nextInt(cards.length);
        for (int i = cards.length - 1; i > 0; i--)
        {
            int j = random.nextInt(i + 1);
            int temp = cards[i];
            cards[i] = cards[j];
            cards[j] = temp;
        }
    }

I really have no clue how to reverse it. I'm assuming there is a function to do so, but I dont know what it is and how to implement it.




Aucun commentaire:

Enregistrer un commentaire