How do I randomly fill an array in Java?

前端 未结 3 1174
温柔的废话
温柔的废话 2020-12-22 04:24

I\'m writing a program that creates a 2D array from a integer n. I then have to fill the array with values from 1 to the nn array size and check to see if it is a magic

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-22 04:48

    You'll need to shuffle the values. You could shuffle each row, then each column, but I suggest you put all the values in one big n * n 1D array and shuffle that, then fill the 2D array.

提交回复
热议问题