samedi 14 mai 2022

Sorting Arrays in Java returning gibberish

Every time I run the code, it returns the array of the two randomly generated numbers as complete and utter gibberish. I am using JDK 18.0.0 and windows 10.

import java.util.concurrent.ThreadLocalRandom;
import java.util.*;
import java.util.Arrays;

public class Mäxchen {

    public static void main(String[] args) {

//beginning of user input for amount of players
        Scanner playerAmountInput = new Scanner(System.in);
            System.out.println("Enter amount of players \n");

            String a = playerAmountInput.nextLine();
            System.out.println("Amount of players are: " + a);
                //end of user input for amount of players

        int playerAmount=2;
        int playerResult=0;
        int die1=ThreadLocalRandom.current().nextInt(1, 6 + 1); //random die 1
        int die2=ThreadLocalRandom.current().nextInt(1, 6 + 1); //random die 2
        int actualResult=0;

        System.out.println(die1+" "+die2);

        int[] arr = { die1, die2 };

         Arrays.sort(arr);


              System.out.println(arr);

    }

}

I am trying to build the german drinking game "Mäxchen" which is similar to Yahtzee. I need to sort the two dice is descending order, and for some reason the output i get is:

[I@7cc355be

All I want, is for the two dice to be displayed in descending order. Any help is greatly appreciated.




Aucun commentaire:

Enregistrer un commentaire