閒得無聊,測試了下輸出11選5,任選5的組合
技術講解:
1.使用Java中的for循環依次數。
2.使用set去重存儲結果
3.外層使用set包裝,將內層的set集合做去重處理,最後輸出的就是11選5中任選5的方案。
import java.util.HashSet;
import java.util.Iterator;import java.util.Set;
public class Test {
public static void main(String[] args) {
test();
}
private static void test() {
Set<Set> set = new HashSet();
for(int i=1;i<12;i++) {
for(int j=1;j<12;j++) {
for(int k=1;k<12;k++) {
for(int l=1;l<12;l++) {
for(int m=1;m<12;m++) {
Set<Integer> tmp = new HashSet();
tmp.add(i);
tmp.add(j);
tmp.add(k);
tmp.add(l);
tmp.add(m);
if(tmp.size()==5) {
set.add(tmp);
}
}
}
}
}
}
Iterator<Set> t=set.iterator();
while(t.hasNext()) {
System.out.println(t.next());
}
}
}