62,614
社区成员
发帖
与我相关
我的任务
分享
int[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
int result = 0;
Random random = new Random();
for (int i = 0, len = 9, index = 0; i < 4; i++) {
index = random.nextInt(len);
result = result * 10 + array[index];
array[index] = array[len--];
}
System.out.println("result -> " + result);
int[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
int result = 0;
Random random = new Random();
for (int i = 0, len = 8, index = 0; i < 4; i++) {
index = random.nextInt(len);
result = result * 10 + array[index];
array[index] = array[len-- + 1];
}
System.out.println("result -> " + result);