One approach - shuffle the array (there is a method in the JDK to do this but you could write your own which is probably what your teacher wants you do do) then use the values at index i and i+1 (i even) as a pair.
Retired horse trader.
Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
James Sabre wrote:One approach - shuffle the array (there is a method in the JDK to do this but you could write your own which is probably what your teacher wants you do do) then use the values at index i and i+1 (i even) as a pair.
Thank you very much for your replies. Regarding the first post, thanks for the suggesting about the shuffle of the array, I am reading about it.
As regards the 2nd post, thank you for the sample code, actually I had already created something along those lines, but the problem is that the same team can be used more than one match, and thus not all teams are being used.
Except that could pair A with F, then again A with G - the random element can be reselected. A similar approach would be to use a List<String>, then remove the random elements instead of only retrieving them.
And welcome to the Ranch!
James, unfortunately, the shuffle method is only available for Lists, not for arrays. Of course you can wrap the array using Arrays.asList and then shuffle that.
And I'm too slow today - M Mangion addressed my first issue, xinghai huang addressed the second...
James, unfortunately, the shuffle method is only available for Lists, not for arrays. Of course you can wrap the array using Arrays.asList and then shuffle that.
I had forgotten that but my post was meant to push the OP in the right direction but it seems that others want to actually do the OP's homework for him.
Retired horse trader.
Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
I'm full of tinier men! And a tiny ad:
a bit of art, as a gift, that will fit in a stocking