双色球选号器的java实现

来源:互联网 发布:vf数据库视频教程网易 编辑:程序博客网 时间:2024/04/30 07:29

package com.byp;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class SelectNum {

 private int lottery[];
 private Map<Integer, String> map = new HashMap<Integer, String>();
 public int[] getLottery() {
  return lottery;
 }
 public void setLottery(int[] lottery) {
  this.lottery = lottery;
 }
 public void run(){
  lottery = new int[6];
  for (int i = 0; i < lottery.length; i++) {
   int x = (int)(Math.random()*32+1);
   if (map.size()==0) {
    map.put(x, "√");
    lottery[i] = x;
   }else{
    x = this.compareMap(x);
    map.put(x, "√");
   }
  lottery[i] = x;
  }
   
 }
 public int compareMap(int x){
  if (map.get(x)!=null) {
   x = (int)(Math.random()*32+1);
   this.compareMap(x);
  }
  return x;
 }
  
 public static void main(String[] args) {
  SelectNum t = new SelectNum();
  t.run();
  int caipiao[] = t.getLottery();
  Arrays.sort(caipiao);
  for (int i = 0; i < caipiao.length; i++) {
   System.out.print(caipiao[i]+"  ");
  }
  System.out.print((int)(Math.random()*15+1));
 }

}

原创粉丝点击