可以考虑用一个list来保存注
改list里面元素表示为
class item{
double money;//加注金额
double count; //加注次数
}
② Java 实现彩票程序
importjava.util.ArrayList;
importjava.util.Collections;
importjava.util.List;
importjava.util.Random;
publicclassMain{
publicstaticvoidmain(String[]args){
//红球选6
List<Integer>redBall=newArrayList<Integer>();
for(inti=0;i<33;i++){
redBall.add(i+1);
}
System.out.println("开奖红球:"+select(redBall,6));
//篮球16选1
List<Integer>blueBall=newArrayList<Integer>();
for(inti=0;i<16;i++){
blueBall.add(i+1);
}
System.out.println("开奖蓝球:"+select(blueBall,1));
}
publicstaticList<Integer>select(List<Integer>list,intcount){
List<Integer>selectedList=newArrayList<Integer>();
Randomrandom=newRandom();
for(inti=0;i<count;i++){
intindex=random.nextInt(list.size());
Integernumber=list.get(index);
selectedList.add(number);
list.remove(index);
}
Collections.sort(selectedList);
returnselectedList;
}
}
③ 用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;i<33;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;i<33;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的彩票
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
/**
* 测试彩票类
* @author doulmi
*
*/
public class LotteryDemo {
public static void main( String[] args ) {
Scanner scanner = new Scanner( System.in );
System.out.print( "请输入要购买的注数:" );
System.out.println();
int buyN = 0;
if ( scanner.hasNextInt() ) {
buyN = scanner.nextInt();
} else {
System.out.println( "请输入正确的数字" );
}
for ( int i = 0; i < buyN; i ++ ) {
Lottery lot = new Lottery();
lot.generate();
System.out.print( "第" );
System.out.print( i );
System.out.print( "注" );
lot.printData();
}
}
}
/**
* 彩票类
* @author Administrator
*
*/
class Lottery {
private static final int NUM_TO_GETOUT = 7;
//能产生的最大数值为99
private static final int MAX_NUM = 35;
public ArrayList< Integer > list;
private int[] result;
public Lottery() {
list = new ArrayList< Integer >();
for ( int i = 1; i <= MAX_NUM; i ++ ) {
list.add( i );
}
result = new int[ NUM_TO_GETOUT ];
}
public void generate() {
Random r = new Random();
for ( int i = 0; i < NUM_TO_GETOUT; i ++ ) {
result[ i ] = list.remove( r.nextInt( list.size() ) );
}
}
/**
* 关于票头的打印。。我不知道票头是什么。
*/
public void pringTitle() {
}
/**
* 实现号码的打印
*/
public void printData() {
for ( int n : result ) {
System.out.print( n );
System.out.print( " " );
}
System.out.println();
}
}
⑤ 用java编写一个彩票抽奖程序
一个简单的程序。
⑥ 用Java程序写一个彩票的模拟程序生成6个红球(1-33的随机数),1个蓝球(1-16的随机数),随机数可以重复
(){
Randomrandom=newRandom();
intredball[]=newint[6];
StringBufferstringBuf=newStringBuffer();
for(inti=0;i<6;){
inttemp=random.nextInt(33)+1;
if(this.isGenerated(redball,temp))
continue;
elsestringBuf.append((redball[i++]=temp)+(i==6?"":","));
}
stringBuf.append("|"+(random.nextInt(16)+1));
returnstringBuf.toString();
}
privatebooleanisGenerated(int[]scope,inttarget){
if(scope==null)returnfalse;
for(inti=0;i<scope.length;i++)
if(target==scope[i])returntrue;
returnfalse;
}