【发布时间】:2014-01-24 05:13:24
【问题描述】:
所以我需要制作一个可以制作彩票游戏的程序。
我的代码支持 4 种游戏,6-42、MegaLotto(6-45)、SuperLotto(6-49) 和 GrandLotto(6-55) 它会询问要玩哪个游戏,输入 1 表示 6-42,依此类推。
该游戏有 10 名玩家,每个玩家在乐透中都有不重复的随机数。 (例如,玩家 1:1,2,3,4,5,6 玩家 2:2,3,4,5,6,7 依此类推。)
有获胜组合 (例如获胜组合:1,2,3,4,5,6)
如何生成一个新号码来代替重复号码? (例如 1,1,2,3,4,5 重复的数字将生成一个新的数字,因此具有 7,1,2,3,4,5)
我的源代码:
public static void main(String args[])
{
int c1[]= new int[10];
int a1[]= new int[6];
int a2[]= new int[6];
int a3[]= new int[6];
int a4[]= new int[6];
int a5[]= new int[6];
int a6[]= new int[6];
int a7[]= new int[6];
int a8[]= new int[6];
int a9[]= new int[6];
int a10[]= new int[6];
int aMaster[]= new int[6];
int a=0,b=0,c=0,d=0;
int x,x1,x2,x3,x4;
String help="";
String holp="";
char went='A';
JDialog.setDefaultLookAndFeelDecorated(true);
int numbers[]= new int[6];
b= Integer.parseInt(JOptionPane.showInputDialog(null,"Type [1] for 6-42\nType [2] for Mega\nType [3] for Super\nType [4] for Grand\nType [5] Go away and never come back!","Play!!!", JOptionPane.WARNING_MESSAGE));
while(b!=5)
{
switch(b)
{
case 1:
holp ="6-42 Lotto:\n";
for(x=0; x<a.length; x++)
{
a1[x]= AllGen(1,42);
}
break;
}
}
}
AllGen 是一种数字生成方法,例如 (1,42) 将生成 1 到 42 之间的随机数。
【问题讨论】:
-
请给您的问题一个合适的标题,以提高覆盖面。您描述的标题非常广泛。
-
Set 通常用于存储唯一编号。如果您必须使用数组,只需为您的数组实现集合操作(“包含?”和“添加/插入”)并循环获取新数字,直到你有足够的数量。使用数组作为集合将保证所有都是唯一的。