标题: 自己写的模拟彩票摇号的Demo [打印本页] 作者: 嗯十一点晚安 时间: 2015-8-4 07:23 标题: 自己写的模拟彩票摇号的Demo public class YaoHao {
public static void main(String[] args) {
// TODO Auto-generated method stub
Set<Integer> set = new HashSet<Integer>();
Random rd = new Random();
Set<Integer> set2 = new HashSet<Integer>();
Random rd2 = new Random();
System.out.println("红色球");
yaohaoR(set, rd);
System.out.println("蓝色球");
yaohaoB(set2,rd2);
}
private static void yaohaoB(Set<Integer> set, Random rd) {
// TODO Auto-generated method stub
for (int temp = 0; temp < 1; temp++) {
set.add(new Integer(rd.nextInt(16)));
}
Iterator<Integer> it = set.iterator();
System.out.println(it.next()+1);
}
private static void yaohaoR(Set<Integer> set2, Random rd2) {
// TODO Auto-generated method stub
for (int temp = 0; temp < 6; temp++) {
set2.add(new Integer(rd2.nextInt(33)));
}
if (set2.size() < 6) {
set2.clear();
yaohaoR(set2, rd2);
} else {
Iterator<Integer> it = set2.iterator();
while (it.hasNext()) {
System.out.println(it.next());
}
}
}