Re-ordering arbitrary an array of integers

前端 未结 4 743
长发绾君心
长发绾君心 2021-01-16 22:04

I have a method that accepts as argument an array of integers and I\'d just change arbitrary the order of its values

public static int[] _game_number = new         


        
4条回答
  •  醉梦人生
    2021-01-16 22:38

    Well, just change the 4 to a variable holding the number of elements.

    While you're at it, you can organize things a bit. Have your GetRandom... method receive the array, check its size (instead of assuming it's 4) and either shuffling it in place if it's something you want, or returning a new array with the same size.

提交回复
热议问题