導航:首頁 > 編程語言 > java中獎概率

java中獎概率

發布時間:2022-04-24 19:50:19

『壹』 java集五福活動概率技術如何實現

『貳』 用java怎麼實現控制中獎率

可以做到!用 Random 得到隨機的數,再根據你的登陸人的身份 控制隨機的次數是多少!
例如:
1 - 20 為中獎, 普通就隨機出 10000個數。會員的話就隨機100個數就好了!

『叄』 這個幸運大抽獎的java代碼,怎麼編寫呢

抽獎就是一個random函數。假如中獎率為1%;
public class Test {
public static void main(String[] args) {
int chance = 100;// 中獎概率,百分之1就是100,千分之一就是1000
double b = Math.random() * chance;
int i = (int) b;
if (i < 1) {
System.out.println("中獎");
}
}
}

『肆』 怎樣用java編程一個雙色球中獎幾率

沒怎麼明白你的意思?

我理解的是不是這樣的:輸入一個六位數(1-33),然後系統不停的隨機,知道隨機到的六個數和這六個數一樣的時候,計算下總共用了多少次?

『伍』 用java完成一個抽獎的程序。 每次運行程序,都會從以下的抽獎結果中隨機顯示一個出來:

生成100個對象,對象有個屬性,其中10個是大獎,40個是小獎,50個是無獎。
放到一個List里。
每次抽中的步驟
1、隨機生成0-List長度之間的數值 ,去取List中的相應對象,並移除這個對象。

代碼如下。:
獎品對象類:

public class PrizeBean {

private String type;

public String getType() {
return eggType;
}

public void setType(String eggType) {
this.eggType = eggType;
}

}
獎品池初始化代碼段:

{
List prizebeanList = new ArrayList();

for (int i = 0; i < 10; i++) {
PrizeBean prizeBean = new PrizeBean();

prizeBean.setType(「大獎「);

prizebeanList.add(prizeBean);
}

for (int i = 0; i < 40; i++) {
PrizeBean prizeBean = new PrizeBean();

prizeBean.setType(「小獎「);

prizebeanList.add(prizeBean);
}

for (int i = 0; i < 50; i++) {
PrizeBean prizeBean = new PrizeBean();

prizeBean.setType(「無獎「);

prizebeanList.add(prizeBean);
}

}
抽獎代碼段:

/**
*獎品池已經空的,肯定返回無獎了。。。

**/

if(prizebeanList.size()==0){
- 沒有中獎哦,下次加油!
return;

}
/**
* 隨機生成,獎品池中獎品數量的數字。。取出獎品池中的數字。。移除記錄。返回。。
*/
int resultnum = (int) (Math.random() * prizebeanList.size());
PrizeBean resultPrizeBean = prizebeanList.get(resultnum);
prizebeanList.remove(resultPrizeBean);

if(resultPrizeBean.getType() .eqauls("大獎"){
- 恭喜,大獎!

}else if(resultPrizeBean.getType() .eqauls("小獎"){
- 運氣不錯哦,小獎!

}else{
- 沒有中獎哦,下次加油!
}.

『陸』 java抽獎程序,可設置不同獎品獲得概率

importjava.awt.EventQueue;
importjava.awt.TextArea;
importjava.awt.TextField;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjava.util.Random;

importjavax.swing.JButton;
importjavax.swing.JFrame;
importjavax.swing.JLabel;
importjavax.swing.JPanel;
importjavax.swing.JTextArea;
importjavax.swing.JTextField;
importjavax.swing.border.EmptyBorder;


{

privateJPanelcontentPane;
privateJTextFieldtextFieldA;
privateJTextFieldtextFieldB;
privateJTextFieldtextFieldC;
privateTextFieldtextField;
;
privateJTextAreatextArea;
/**
*Launchtheapplication.
*/
publicstaticvoidmain(String[]args){
EventQueue.invokeLater(newRunnable(){
publicvoidrun(){
try{
LuckySelectframe=newLuckySelect();
frame.setVisible(true);
}catch(Exceptione){
e.printStackTrace();
}
}
});
}

/**
*Createtheframe.
*/
publicLuckySelect(){
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100,100,450,251);
contentPane=newJPanel();
contentPane.setBorder(newEmptyBorder(5,5,5,5));
contentPane.setLayout(null);
setContentPane(contentPane);

JLabellblA=newJLabel("A");
lblA.setBounds(10,128,54,15);
contentPane.add(lblA);

JLabellblB=newJLabel("B");
lblB.setBounds(124,128,54,15);
contentPane.add(lblB);

JLabellblC=newJLabel("C");
lblC.setBounds(254,128,54,15);
contentPane.add(lblC);

textFieldA=newJTextField();
textFieldA.setBounds(30,125,66,21);
contentPane.add(textFieldA);
textFieldA.setColumns(10);

textFieldB=newJTextField();
textFieldB.setColumns(10);
textFieldB.setBounds(149,125,66,21);
contentPane.add(textFieldB);

textFieldC=newJTextField();
textFieldC.setColumns(10);
textFieldC.setBounds(264,125,66,21);
contentPane.add(textFieldC);

textField=newTextField();
textField.setBounds(98,167,157,21);
contentPane.add(textField);
textField.setColumns(10);

textFieldResult=newJTextField();
textFieldResult.setBounds(280,167,66,21);
contentPane.add(textFieldResult);
textFieldResult.setColumns(10);
textFieldA.setText("10");
textFieldB.setText("10");
textFieldC.setText("10");

JButtonbutton=newJButton("u62BDu5956");
button.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEvente){
select();
}
});
button.setBounds(0,166,93,23);
contentPane.add(button);

textArea=newJTextArea();
textArea.setBounds(30,31,306,83);
contentPane.add(textArea);
}

protectedvoidselect(){
//TODOAuto-generatedmethodstub
intaNum=Integer.decode(textFieldA.getText());
intbNum=Integer.decode(textFieldB.getText());
intcNum=Integer.decode(textFieldB.getText());
Randomr=newRandom();
intrandom=r.nextInt(aNum+bNum+cNum);
if(random<=aNum){
textFieldA.setText(Integer.toString(Integer.decode(textFieldA.getText())-1));
textArea.append(Integer.toString(random)+"抽中了A ");
}elseif(random<=aNum+bNum){
textFieldB.setText(Integer.toString(Integer.decode(textFieldB.getText())-1));
textArea.append(Integer.toString(random)+"抽中了B ");
}elseif(random<=aNum+bNum+cNum){
textFieldC.setText(Integer.toString(Integer.decode(textFieldC.getText())-1));
textArea.append(Integer.toString(random)+"抽中了C ");
}

}
}

『柒』 求java演算法:根據物品的數量來確定抽獎的概率(當物品數量為0時無論如何都不可能選到)

public class Lottery {

private int m = 1000;//發放獎券的數量
private int n = 2;//獎品的數量

public boolean getLottery(){
boolean isLottery = false;
double d = (double)n/(double)m;//中獎概率
double r = Math.random();//0~1之間的隨機數,包括0
if(r<d){//如果隨機數小於概率 那麼中獎
n--;//獎品數量-1
isLottery = true;
}
m--;//獎券數量-1
return isLottery;
}

}

『捌』 初學java,突然想算一下買20年雙色球中一等獎概率,用java編譯時沒出錯,運行時出錯了。問一下哪錯了。

classSsq{
publicstaticvoidmain(String[]args){
//Gailvaa=newZonggailv();
System.out.println(Zonggailv.g());
}
}

java裡面一般用println輸出。

『玖』 JAVA抽獎的演算法

那你可以再1-10000之間隨即嘛,概率小的獎品設置為1-10,概率大的設置為11-1000,最後隨即出來的數判斷一下在那個區間就可以了.
實體類,就是寫一個JAVA BEAN嘛,裡面記載獎品名字和數量啊,不懂可以追問

『拾』 一等獎1個2等獎5個1等獎概率1%每人抽10次java怎麼寫

中獎率 1%,每人抽 10 次,也就是說 10 個人就可以抽 100 次,概率上來說 10 個人必中獎?假設邏輯是這樣的,可以這樣設計:
1、先寫定義一個表示概率的數組 ratio,這個數組最多可以存 100 個數字,每個數字的值不能重復,范圍是 0 到 100,表示 100%。現在你的中獎率是 1%,那麼就存一個數字。
2、定義一個是否中將的布爾型變數 win;
每次抽獎用隨機正整數對 100 取余,再將結果拿到 ratio 數組中查找,如果找到就將 win 賦值為 true,表示中獎。如果沒找到就對 win 賦值為 false,表示沒有中獎。

閱讀全文

與java中獎概率相關的資料

熱點內容
機明自動編程軟體源碼 瀏覽:325
php埠號設置 瀏覽:540
phperegreplace 瀏覽:319
androidgridview翻頁 瀏覽:537
ssh協議編程 瀏覽:634
如何開我的世界電腦伺服器地址 瀏覽:861
玄關pdf 瀏覽:609
程序員學習論壇 瀏覽:940
程序員的毒雞湯怎麼做 瀏覽:547
安卓怎麼降級軟體到手機 瀏覽:281
雲與伺服器入門書籍推薦產品 瀏覽:636
delphi編程助手 瀏覽:761
電腦遇到伺服器問題怎麼辦 瀏覽:515
加工中心編程結束方法 瀏覽:295
了解什麼是web伺服器 瀏覽:139
面向對象的編程的基本特徵 瀏覽:717
php定時執行任務linux 瀏覽:787
php數組中刪除元素 瀏覽:724
螢石雲伺服器視頻 瀏覽:269
防火牆配置伺服器熱備的虛擬地址 瀏覽:189