本帖最后由 hmhm123 于 2019-3-28 17:04 编辑
[Java] 纯文本查看 复制代码 public class Demo6 {
public static void main(String[] args) {
String [] str ={"篮球","足球","鞋子","安全"};
Random rd = new Random();
Scanner sc = new Scanner(System.in);
List<Integer> list = new ArrayList<>();
Map<String,String> map = new HashMap<>();
for (int i = 0; i < 6; i++) {
list.add(rd.nextInt(10));
}
for (String s : str) {
map.put(quhuoma(list),s);
}
System.out.println(map);
String quhuoma = sc.next();
Set<Map.Entry<String,String >> set = map.entrySet();
for (Map.Entry<String, String> entry : set) {
if (entry.getKey().equals(quhuoma)) {
System.out.println(entry.getValue());
return;
}
}
System.out.println("对不起!取货码有误");
}
public static String quhuoma(List list) {
Collections.shuffle(list);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 6; i++) {
String a = list.get(i) + "";
sb.append(a);
}
return sb.toString();
}
} |