//新建一个HashSet
HashSet<String> sixHashSet = new HashSet<String>();
//满6位时结束循环
while (sixHashSet.size() != 6) {
String temp = Integer.toString((int) (Math.random() * 10));
sixHashSet.add(temp);
}
//拼接结果
String sixString = "";
for (String string : sixHashSet) {
sixString = sixString + string;
}
//打印结果
System.out.println(sixString);
时间: 2024-10-13 08:01:50