自己写的,不懂可以问我
import javautilRandom;
import javaawt;
import javaawtevent;
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;i<33;i++)
{
a[i] = i;
}
fsetLayout(new BorderLayout());
faddWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
Systemexit(0);
}
});
}
public void init()
{
tfaddActionListener(this);
Button b = new Button("开始");
baddActionListener(this);
fadd(tf,"North");
fadd(b);
fsetSize(300,300);
fsetVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(egetActionCommand()equals("开始"))
//tfsetText(""+(rdnextInt(33)+1)+" "+(rdnextInt(33)+1)+" "+(rdnextInt(33)+1)+" "+(rdnextInt(33)+1)+" "+(rdnextInt(33)+1)+" "+(rdnextInt(33)+1)+" 蓝色球号码:"+(rdnextInt(15)+1));
{
/rr = new Random()nextInt(33);
rm = new Random()nextInt(33);/
for(i=0;i<33;i++)
{
rr = new Random()nextInt(33);
rm = new Random()nextInt(33);
Systemoutprint(rr+" ");
k=a[rm];
a[rm]=a[rr];
a[rr]=k;
}
tfsetText("红色球号码:"+(a[0]+1)+" "+(a[1]+1)+" "+(a[2]+1)+" "+(a[3]+1)+" "+(a[4]+1)+" "+(a[5]+1)+" 蓝色球号码:"+(rdnextInt(15)+1));
}
}
public static void main(String[] args)//throws Exception
{
new shuangSeQiu()init();
}
}
public class RandomDemo {
public static void main(String[] args) {
LotteryTicket lt = new LotteryTicket();
int red[] = ltgetRed();
Systemoutprint("随机生成的红球为:");
for(int i=0;i<6;i++){
Systemoutprint(" "+red[i]);
}
Systemoutprint("\t蓝球为:"+ltgetBlue());
}
}
class LotteryTicket{ **生成类
private int[] red = new int[6];
public int[] getRed(){ //返回红球
int i =0;
for(;i<6;i++){
red[i] = (int)(Mathrandom()33) +1;
for(int j=0;j<i;j++){ //保证了重复,我个从认为这个**好像不能重复吧
if(red[i]==red[j]){
red[i] = (int)(Mathrandom()33) +1;
j=0;
}
}
}
return red;
}
public int getBlue(){ //返回蓝球
return (int)(Mathrandom()16) +1;
}
}
以上就是关于用JAVA编写一个福利彩票机选模拟器,使用随机数方法全部的内容,包括:用JAVA编写一个福利彩票机选模拟器,使用随机数方法、用Java程序写一个彩票的模拟程序生成6个红球(1-33的随机数),1个蓝球(1-16的随机数),随机数可以重复、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)