双色球
最近身边很多人玩双色球。。我也买了几期。下面是双色球模拟程序,代码如下:[java]package Test;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.SQLException;import java.sql.Statement;import java.util.ArrayList;import java.util.List;import Test.util.ConnectionUtil;/**6个为红球(1—33),1个为蓝球(1—16)*/public class ColorBall {public static void main(String[] args) {try {Connection conn=ConnectionUtil.getConnection();Statement stmt = conn.createStatement();PreparedStatement ps=null;String sql = "insert into ball values(BALLID_SEQ.NEXTVAL,?,?,?,?,?,?,?,sysdate)";ps=conn.prepareStatement(sql);//循环购买双色球2400000注for(int c=0;c<2400000;c++){List luckBalls=makeLuck();for(int i=0;i<luckBalls.size();i++){String num=Integer.toString((Integer)luckBalls.get(i));ps.setString(i+1,num);}ps.executeUpdate();}stmt.close();conn.close();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}//产生一期幸运球public static List makeLuck(){List balls=new ArrayList();List luckBalls=new ArrayList();for(int i=0;i<33;i++){balls.add(i+1);}for(int i=0;i<6;i++){int luckIndex=(int)(Math.random()*(balls.size()));luckBalls.add(balls.get(luckIndex));balls.remove(luckIndex);}luckBalls.add((int)(Math.random()*16)+1);return luckBalls;}}package Test;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.SQLException;import java.sql.Statement;import java.util.ArrayList;import java.util.List;import Test.util.ConnectionUtil;/**6个为红球(1—33),1个为蓝球(1—16)*/public class ColorBall {public static void main(String[] args) {try {Connection conn=ConnectionUtil.getConnection();Statement stmt = conn.createStatement();PreparedStatement ps=null;String sql = "insert into ball values(BALLID_SEQ.NEXTVAL,?,?,?,?,?,?,?,sysdate)";ps=conn.prepareStatement(sql);//循环购买双色球2400000注for(int c=0;c<2400000;c++){List luckBalls=makeLuck();for(int i=0;i<luckBalls.size();i++){String num=Integer.toString((Integer)luckBalls.get(i));ps.setString(i+1,num);}ps.executeUpdate();}stmt.close();conn.close();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}//产生一期幸运球public static List makeLuck(){List balls=new ArrayList();List luckBalls=new ArrayList();for(int i=0;i<33;i++){balls.add(i+1);}for(int i=0;i<6;i++){int luckIndex=(int)(Math.random()*(balls.size()));luckBalls.add(balls.get(luckIndex));balls.remove(luckIndex);}luckBalls.add((int)(Math.random()*16)+1);return luckBalls;}}数据库情况:建表语句:[sql]-- Create tablecreate table BALL(OPENID VARCHAR2(10) not null,RED1 VARCHAR2(10) not null,RED2 VARCHAR2(10) not null,RED3 VARCHAR2(10) not null,RED4 VARCHAR2(10) not null,RED5 VARCHAR2(10) not null,RED6 VARCHAR2(10) not null,BLUE1 VARCHAR2(10) not null,DATETIME DATE)tablespace USERSpctfree 10initrans 1maxtrans 255storage(initial 64next 8minextents 1maxextents unlimited);-- Create/Recreate primary, unique and foreign key constraintsalter table BALLadd constraint ID primary key (OPENID)using indextablespace USERSpctfree 10initrans 2maxtrans 255storage(initial 64Knext 1Mminextents 1maxextents unlimited);-- Create/Recreate indexescreate unique index IDX_TEST on BALL (OPENID DESC)tablespace USERSpctfree 10补充:软件开发 , Java ,
上一个:怎么定义类,定义方法
下一个:java开发JMS for Jboss4
- 更多JAVA疑问解答:
- java怎么在线读取ftp服务器上的文件内容
- 关于程序员的职业规划
- HTML和JSP矛盾吗?
- java小程序如何打包?
- java怎么split路径文件名?
- jsp+javaBean中Column 'ordersPrice' specified twice的错误
- Java TCP/IP Socket网络编程系列
- 大家来讨论一下我到底该用什么好?Swing 还是 JavaFX
- 关于Hibernate实体自身多对一的抓取问题
- 关于apache2+tomcat群集出现的问题
- spring 获取上下文问题
- SSH 导入导出excel 谁有这块的资料吗?
- Ext TreePanel 刷新问题
- springmvc 加载一个jsp页面执行多个方法 报404
- checkbox数组action怎么向页面传值