lundi 25 janvier 2021

How to get randomly a pair elements from a 2d Array (java)

I have the following Array :

arr= new int[][] { { 20, 0 }, { 2, 1 }, { 3, 2 }, { 1, 0 } };

I want getting randomly one lement from arr. For example : [3,2] or [20,0]

I'm using the following code :

Random r=new Random();        
    int rd= rand.nextInt(arr.length);



Aucun commentaire:

Enregistrer un commentaire