java随机生成一注双色球并写入文件


package com.happy.test;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
* @author: (le.qiao)
* @e-mail: [email protected]
* @myblog: http://qiaolevip.iteye.com
* @date: 2012-10-30
*
*/
public class ShuangSeQiu {

/**
* 执行并写入本地文件,可上传至投注网站,如:lecai.com
*
* @param args
*/
public static void main(String[] args) {
try {
BufferedWriter bw = new BufferedWriter(new FileWriter("E:/shuangseqiu.txt"));
for (int i = 0; i < 10; i++) {
bw.write(randemNumber());
bw.newLine();
}
bw.flush();
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}

/**
* 生成一串双色球数据
*
* @return
*/
public static String randemNumber() {
StringBuffer sb = new StringBuffer();
List zong = new ArrayList();
List balls = new ArrayList();
for (int i = 1; i < 34; i++) {
balls.add(i);
}
Collections.shuffle(balls);
for (int i = 0; i < 6; i++) {
zong.add(balls.get(i));
}
Collections.sort(zong);
balls.removeAll(balls);
for (int i = 1; i < 17; i++) {
balls.add(i);
}
for (int i = 0; i < 6; i++) {
sb.append(zong.get(i) > 9 ? zong.get(i) : "0" + zong.get(i)).append(",");
}
sb = new StringBuffer(sb.substring(0, sb.length() - 1));
Collections.shuffle(balls);
sb.append("|").append(zong.get(0) > 9 ? zong.get(0) : "0" + zong.get(0));
return sb.toString();
}
}

你可能感兴趣的:(JAVA)