# java实现对n个数字随机排序

0
[待解决问题]

``````                                                  2 3 1 4 5

5 4 1 2 3
``````

who can help me？？？？？？

（自己实在是太菜了）

public static void main(String[] args) {
String[] s = new String[]{"1", "2", "3", "4", "5"};
List<String> list = new ArrayList<>(Arrays.asList(s));
for (int i = 0; i < 100; i++) {
Collections.shuffle(list);
System.out.println(list);
}
}

agnils 3年前

0

0

yytxdy | 园豆：1680 (小虾三级) | 2021-04-17 10:06

@会长: 太对了我的哥

public static void main(String[] args) {
String[] s = new String[]{"1", "2", "3", "4", "5"};
List<String> list = new ArrayList<>(Arrays.asList(s));
for (int i = 0; i < 100; i++) {
Collections.shuffle(list);
System.out.println(list);
}
}

0
``````var list =  [];
var i = 0;
while(i < 100)
{
var result = 你选择的方法();
if(list.contains(result))
{
contine;
}
print(result);
i++;
}
``````

j就是每次运行之后只能生成一条，怎么样才能多生成几条不同的

@灯儿: 没明白你啥意思，Java里肯定有产生随机数的函数。

0

0

public static void main(String[] args) {
String[] s = new String[]{"1", "2", "3", "4", "5"};
List<String> list = new ArrayList<>(Arrays.asList(s));
for (int i = 0; i < 100; i++) {
Collections.shuffle(list);
System.out.println(list);
}
}

agnils | 园豆：205 (菜鸟二级) | 2021-04-19 14:28

您需要登录以后才能回答，未注册用户请先注册