「java彩票模拟」java彩票项目源码
本篇文章给大家谈谈java彩票模拟,以及java彩票项目源码对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、用JAVA便携一个程序,用来模拟随机生成一个36选7的彩票号码
- 2、Java模拟生成双色球
- 3、用JAVA编写一个福利彩票机选模拟器,使用随机数方法
- 4、用Java程序写一个彩票的模拟程序生成6个红球(1-33的随机数),1个蓝球(1-16的随机数),随机数可以重复
用JAVA便携一个程序,用来模拟随机生成一个36选7的彩票号码
就是从36个数中选出7个,这36个数是什么可以自己指定,但必须保证不重复,我写的一个代码
public
class
test
{
public
static
void
main(String[]
args)
{
int[]
a
=
new
int[36];
for(int
i
=
0;
i
36;
++i)
a[i]
=
i+1;
for(int
i
=
0;
i
5;
++i)
randomSelect(a,
7);
}
static
void
randomSelect(int[]
a,
int
n)
{
randomShuffle(a,
7);
for(int
i
=
0;
i
n;
++i)
System.out.print(a[i]
+
"
");
System.out.println();
}
static
void
randomShuffle(int[]
a,
int
n)
{
for(int
i
=
0;
i
n;
++i)
{
int
r
=
(int)(Math.random()
*
a.length);
int
tmp
=
a[i];
a[i]
=
a[r];
a[r]
=
tmp;
}
}
}
Java模拟生成双色球
public void main (String[] args){
int[] red=new int[7];
int blue=0;
for(int i=0;i7;i=i+1){
red[i]=getRandom(33);
//判断重复
while(true){
boolean needcheck=false;
for(int k=0;ki;k=k+1) { if(red[i]==red[k]){ needcheck=true; }}
if(needcheck){red[i]=red[i]+1; if(red[i]==34){red[i]=1}}else{break;}
}
//判断重复结束
}
//红球赋值结束
blue=getRandom(16);
System.out.println("生成的红球为:"+ red[0]+red[1]+red[2]+red[3]+red[4]+red[5]+red[6]);
System.out.println("生成的蓝球为:"+ );
}
public int getRandom(int Max){
return Math.floor(Math.random()*33)+1;
}
用JAVA编写一个福利彩票机选模拟器,使用随机数方法
自己写的,不懂可以问我
import java.util.Random;
import java.awt.*;
import java.awt.event.*;
public class shuangSeQiu implements ActionListener{
int i,k;
static int rm,rr;
int [] a = new int [33];
Frame f = new Frame("双色球随机数");
TextField tf = new TextField();
Random rd = new Random();
public shuangSeQiu()
{
for(i=0;i33;i++)
{
a[i] = i;
}
f.setLayout(new BorderLayout());
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
public void init()
{
tf.addActionListener(this);
Button b = new Button("开始");
b.addActionListener(this);
f.add(tf,"North");
f.add(b);
f.setSize(300,300);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("开始"))
//tf.setText(""+(rd.nextInt(33)+1)+" "+(rd.nextInt(33)+1)+" "+(rd.nextInt(33)+1)+" "+(rd.nextInt(33)+1)+" "+(rd.nextInt(33)+1)+" "+(rd.nextInt(33)+1)+" 蓝色球号码:"+(rd.nextInt(15)+1));
{
/*rr = new Random().nextInt(33);
rm = new Random().nextInt(33);*/
for(i=0;i33;i++)
{
rr = new Random().nextInt(33);
rm = new Random().nextInt(33);
System.out.print(rr+" ");
k=a[rm];
a[rm]=a[rr];
a[rr]=k;
}
tf.setText("红色球号码:"+(a[0]+1)+" "+(a[1]+1)+" "+(a[2]+1)+" "+(a[3]+1)+" "+(a[4]+1)+" "+(a[5]+1)+" 蓝色球号码:"+(rd.nextInt(15)+1));
}
}
public static void main(String[] args)//throws Exception
{
new shuangSeQiu().init();
}
}
用Java程序写一个彩票的模拟程序生成6个红球(1-33的随机数),1个蓝球(1-16的随机数),随机数可以重复
import java.util.Random;
import java.util.Scanner;
public class DoubleBalls {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("是否机选一组双色球号码?(Y/N)");
Scanner input = new Scanner(System.in);
char a = input.next().charAt(0); // 输入一个char字符,0位即是第一位
if (a == 'Y' || a == 'y') {
Random suiji = new Random(); // 创建suiji方法
int blue = suiji.nextInt(16);//从0到16中选一个数字个蓝球
while(blue==0){
blue=suiji.nextInt(16);
}//如果选到了0,再选一次给blue
int red[] = new int[6];// 用一个6个元素的数组装红球
for (int i = 0; i 6; i++) {
red[i] = suiji.nextInt(33); // 随机分配0到33的整数
if (red[i] == 0) {i--;}
if (i == -1) {i = 0;}
for (int j = 0; j i; j++) {
while (red[i] == red[j]) {i--;}// 发现相同的从新回去生成一个
}
}
System.out.print("红球:");
for (int k = 0; k red.length; k++) {
System.out.print(red[k] + " ");// 输出数组red
}
System.out.print("蓝球:"+blue);
} else
System.out.println("fuck you~");
}
}
应该可以了,可以产生一组。。。如果楼主你中头奖了,送我套房好了哈^0^
关于java彩票模拟和java彩票项目源码的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。