如何使用10-99的1000个随机数格式化数组?

时间:2015-12-05 00:46:53

标签: arrays random numbers

这可以在一行上打印数字,但我想格式化数组,以便每行有20个数字。我该怎么做呢?

Random r = new Random();

int[] myArray = new int[1000];        
for (int counter = 0; counter < myArray.length; counter++) {
    int store = 10 + r.nextInt(89);
    myArray[counter] = store;
    System.out.print(myArray[counter]);
}

1 个答案:

答案 0 :(得分:0)

Random r = new Random();

int[] myArray = new int[1000];        
for (int counter = 0; counter < myArray.length; counter++) {
    int store = 10 + r.nextInt(89);
    myArray[counter] = store;
    if(counter != 0 && counter % 20 == 0)
        System.out.print("\n");
    System.out.print(myArray[counter] + " ");
}