可以不用中断。你只要写个段码的数值,然后在数组里加一个变量。比如“uchardm[]={0xc0,0xa4,0xf9}“每次按下一个键数组里的变量就加一。做按键的时候要记住去斗。归0的按键就更好写了,只要按下数组里的变量等于0就行了。希望能帮到你,亲~
窗体上一个文本框,一个按钮:
Option Explicit
Private Sub Command1_Click()
Dim n As Integer
Dim m As Integer
Dim x As Integer
n = 1234
m = 5678
Randomize
x = Int(Rnd (5678 - 1234 + 1) + 1234)
Do While x Mod 4 = 0
x = Int(Rnd (5678 - 1234 + 1) + 1234)
Loop
Text1Text = x
End Sub
(1)这次抽奖活动,中奖的可能性是:100÷(20+30+50)=100%;(2)第一个人抽奖中一等奖可能性是:20÷(20+30+50)=15,中二等奖的可能性是:30÷(20+30+50)=310,中三等奖的可能性是:50÷(20+30+50)=12;(3)抽奖到一半,已经有10人中一等奖,15人中二等奖,25人中三等奖;则:一等奖还有10个,二等奖还有15个,三等奖还有25个,10+15+25=50(个),这里李明第51个抽奖,中一等奖的可能性是:10÷50=15,中二等奖的可能性是:15÷50=310,中三等奖的可能性是:25÷50=12;故答案为:100%,15,310,12,15,310,12.
Private Sub Command1_Click()
Randomize
Label1Caption = Fix(Rnd 10)
Label2Caption = Fix(Rnd 10)
Label3Caption = Fix(Rnd 10)
LabelshuziCaption = Fix(Rnd 10)
If Label1Caption = LabelshuziCaption Or
Label2Caption = LabelshuziCaption Or
Label3Caption =LabelshuziCaption Then
Image1Visible = True
Else
Image1Visible = False
End If
End Sub
注:此段代码可以实现自动选出三个号 Label1 Label2 Label3为选出的三个号
import javaawtGridLayout;
import javaawteventActionEvent;
import javaawteventActionListener;
import javautilArrayList;
import javautilList;
import javaxswingJButton;
import javaxswingJFrame;
import javaxswingJOptionPane;
import javaxswingJPanel;
public class Lottery extends JFrame {
private List<JButton> list = new ArrayList<JButton>();
private final static int SIZE = 9;
private String[] info = new String[SIZE];
private int index;
private boolean flag = true;
public static void main(String[] args) {new Lottery();}
public Lottery() {init();}
private void init() {
thissetTitle("随机抽检");
thissetSize(300, 300);
thisadd(createPanel());
thissetLocationRelativeTo(null);
thissetResizable(false);
thissetDefaultCloseOperation(JFrameEXIT_ON_CLOSE);
thissetVisible(true);
}
private JPanel createPanel() {
JPanel panel = new JPanel();
panelsetLayout(new GridLayout(3, 3));
for (int i = 0; i < SIZE; i++) {
listadd(createButton());
}
for (int i = 0; i < SIZE; i++) {
paneladd(listget(i));
}
for (int i = 0; i < SIZE; i++) {
info[i] = "谢谢参与";
}return panel;
}
private JButton createButton() {
JButton button = new JButton();
buttonaddActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (flag) {
index = ((int) (Mathrandom() 100)) % 9;
info[index] = "中奖啦";
for (int i = 0; i < SIZE; i++) {
listget(i)setText(info[i]);
}
if(((JButton)egetSource())getText()equals("中奖啦")){
JOptionPaneshowMessageDialog(null, "恭喜您,中奖啦!");
}else{JOptionPaneshowMessageDialog(null, "很遗憾,您没有中奖!");}
flag = false;
}else{
info[index] = "谢谢参与";
for (int i = 0; i < SIZE; i++) {
listget(i)setText("");
}
flag = true;
}
}
});
return button;
}
}
帮你写了,你运行看看。
以上就是关于编写一个C语言抽奖程序,1到1000以内的数反复滚动,随机按一下键,只显全部的内容,包括:编写一个C语言抽奖程序,1到1000以内的数反复滚动,随机按一下键,只显、VB程序设计,随机抽奖,每次产生一个区间为n到m的中奖号码,并自动排、用随机数编写一个抽奖游戏,一等奖不超过 10%,二等奖不超过 20%,三等奖不超过 30%, 未中奖 40%。等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)