導航:首頁 > 編程語言 > java彩票系統

java彩票系統

發布時間:2023-10-05 03:38:29

① 如何使用java語言程序模擬彩票抽獎系統中的加住

可以考慮用一個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;
}

閱讀全文

與java彩票系統相關的資料

熱點內容
js有二維數組嗎 瀏覽:594
熹妃q傳的網路什麼時候可以修好 瀏覽:165
key文件linux 瀏覽:990
java調用hessian 瀏覽:486
福建聚合網路公司怎麼樣 瀏覽:302
魅族手機備份文件夾 瀏覽:204
電腦c盤騰訊文件夾有什麼用 瀏覽:467
編程語言哪個最好就業 瀏覽:912
能不能找到cad之前打開的文件 瀏覽:259
怎樣設置文件夾許可權 瀏覽:60
oppo手機如何把圖片壓縮成文件 瀏覽:808
載入語言文件失敗 瀏覽:884
招聘plc編程屬於什麼職位類別 瀏覽:580
appstore改區後購買記錄 瀏覽:538
win10管理該文件沒有與之關聯的程序 瀏覽:799
手機里qt是什麼文件夾 瀏覽:48
筆記本關閉開機密碼 瀏覽:672
無法定位程序輸入點inetntop 瀏覽:22
java修改文件編碼 瀏覽:12
js判斷火狐 瀏覽:229

友情鏈接