当前位置:首页 » 编程语言 » java彩票系统

java彩票系统

发布时间: 2024-04-05 09:25:10

1. java澶х炲府鎴戠湅鐪嬩綔涓氾纴锅氢竴涓25阃5镄勫僵绁ㄦ満锛屾垜锅氱殑绠椾笉绠楁瘆杈幂亩娲佺殑锛

铏界劧绠娲侊纴浣嗕笉瑙勮寖锛屾渶濂芥槸鎸夎勮寖瑕佹眰璧帮绂渚嫔傦细杈揿嚭镄25锛屾渶濂藉啓鎴愶细
System.out.print("褰╃エ镐婚暱搴︿负锛"+ArrayNum.length+"\n"+"闅忔満鍙风爜涓猴细");
for(int i =0; i<25;i++) 链濂藉啓鎴愶细for(int i =0; i<arrayNum.length;i++)

2. java璇瑷瀹炵幇涓涓鎽囧彿绯荤粺锛屼絾鏄鍙浠ュ唴閮ㄨ惧畾涓濂栧悕鍗曡繖涓镐庝箞瀹炵幇锛

1銆佺亩鍗曟带鍒跺彴绋嫔簭濡备笅锛屽傞渶鐣岄溃闇瑕佽嚜宸卞姞涓銆

package ;

import java.util.HashSet;
import java.util.Random;
import java.util.Scanner;
import java.util.Set;

/**
* @author bufei
* @datetime 2020骞8链31镞15:54:11
*/


public class YaoHao {
public static void main(String[] args) {
String xian = "= = = = = = = = =";
// 璧风偣 缁堢偣 濂栦釜鏁 鎸囧畾镄勫彿镰佷釜鏁
int start = 0, end = 0, prizeNum = 0, defaNum = 0;
System.out.println(xian);
System.out.println("娆㈣繋浣跨敤xxx 鎶藉栫郴缁燂紒");
System.out.println(xian);
Scanner scanner = new Scanner(System.in);
System.out.println("璇疯緭鍏ュ彿镰佽寖锲翠緥濡 1 10锛");
start = scanner.nextInt();
end = scanner.nextInt();
System.out.println("璇疯緭鍏ュ栭”涓鏁帮细");
prizeNum = scanner.nextInt();
System.out.println("璇疯緭鍏ユ寚瀹氢腑濂栧彿镰佷釜鏁帮纴涓嶆寚瀹氲疯緭鍏0锛");
defaNum = scanner.nextInt();
int[] defa = new int[defaNum];
if (defaNum != 0) {

System.out.println("璇疯緭鍏ユ寚瀹氱殑涓濂栧彿镰侊纴绌烘牸闅斿紑:");
for (int i = 0; i < defaNum; i++) {
defa[i] = scanner.nextInt();
}
}
System.out.println(xian);
System.out.println("链娆℃娊濂栦腑濂栧彿镰佷负锛");
for (int num : randomDraw(start, end, prizeNum, defa)) {
System.out.print(num+" ");
}

}

/**
* @param start 鎶藉栬寖锲磋捣镣
* @param end 鎶藉栧彿镰佽寖锲寸粓镣
* @param prizeNum 涓濂栧彿镰佷釜鏁
* @param defa 鎸囧畾涓濂栧彿镰
* @return
*/
public static Set<Integer> randomDraw(int start, int end, int prizeNum, int[] defa) {

Set<Integer> set = new HashSet<>();
// 链鎸囧畾涓濂栧彿镰
if (defa.length == 0) {
//闅忔満鎶 prizeNum 涓濂
while (set.size() < prizeNum) {
set.add(new Random().nextInt(end - start + 1) + start);
}

return set;
} else {
//鎸囧畾浜嗕腑濂栧彿镰
//鎶婃寚瀹氱殑鍙风爜锷犲叆杩涘幓
for (int num : defa) {
set.add(num);
}
//濡傛灉娌℃湁鍏ㄩ儴鎸囧畾 鍒欑户缁鎶藉墿浣欑殑濂栭”
while (set.size() < prizeNum - defa.length) {
set.add(new Random().nextInt(end - start + 1) + start);
}
return set;

}
}

}

2銆佽繍琛屾晥鏋滃傚浘

链鎸囧畾涓濂栧彿镰

3. 用java编写一个彩票抽奖程序

我写给你,如果是本专业,以后要多多学习。JDK 1.6

import java.awt.GridLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Iterator;
import java.util.Random;
import java.util.Set;
import java.util.TreeSet;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;

public class LuckyDrawn {

private JFrame f = new JFrame("Lucky Drawn");
private JButton btn = new JButton("Drawn");
private JTextField result = new JTextField("Result");
private static final int MIN = 1;
private static final int MAX = 30;
private static final int RESULT_COUNT = 7;

public LuckyDrawn(){
f.add(btn);
f.add(result);
result.setEditable(false);

btn.addMouseListener(new MouseListener(){

public void mouseClicked(MouseEvent e) {

Random rand = new Random();

Set<Integer> set = new TreeSet<Integer>();

while(set.size() < RESULT_COUNT){
set.add(new Integer(rand.nextInt(MAX)+ 1));
}

StringBuffer sb = new StringBuffer("Lucky numbers are: ");
for (Iterator iter = set.iterator(); iter.hasNext();) {
sb.append(((Integer) iter.next()).intValue()).append(", ");
}

result.setText(sb.substring(0, sb.length() - 2).toString());
f.pack();
}

public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
});

f.setLayout(new GridLayout(2, 1));
f.setVisible(true);
f.setLocation(500, 200);
f.pack();
f.validate();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

public static void main(String[] args) {
new LuckyDrawn();
}

}

热点内容
php输出array 发布:2024-11-28 13:30:15 浏览:745
汽车安卓大屏的高德怎么卸载 发布:2024-11-28 13:26:00 浏览:701
androidbitmap失真 发布:2024-11-28 13:05:04 浏览:866
php图片识别文字 发布:2024-11-28 12:55:23 浏览:823
redis永久缓存 发布:2024-11-28 12:37:40 浏览:56
php是自学网 发布:2024-11-28 12:33:57 浏览:733
php采集系统 发布:2024-11-28 12:32:04 浏览:908
数据库恢复的实现技术 发布:2024-11-28 12:25:26 浏览:6
压缩图档 发布:2024-11-28 12:25:23 浏览:424
自定义缓存 发布:2024-11-28 12:25:07 浏览:236